Heaven/TQA Posted July 19, 2005 Share Posted July 19, 2005 some of you might have seen the sinistar-like... thread in the homebrew forum... i am just implementing my movements for the enemies into 6502 but i run into trouble as i haven't used signed fixed point maths (if ever needed...) look what i am doing * vex=(px-ex)/8 * vey=(py-ey)/8 * ex=ex+vex * ey=ey+vey calc ldx #3 lda px sec sbc ex bmi calc_minus clc lsr @ lsr @ lsr @ sta vex clc adc ex sta ex rts calc_minus clc asl @ asl @ asl @ sta vex clc adc ex sta ex rts what i am doing wrong as it does not work? f.e. px-ex = 100-160 = -60 = $c4 now as its minus i will do *2 = $ff88 * 2 = $ff10 *2 = $fe20 so looking just at the low-byte = $20 but should it not be -60 div 8 = -7.5 = -7 = $f9???? what i am doing wrong? Quote Link to comment Share on other sites More sharing options...
supercat Posted July 19, 2005 Share Posted July 19, 2005 what i am doing wrong? What are you using "asl" for if this is supposed to be a divide-by-eight? I would suggest something like the following: idiv8: ; Divide the number in the accumulator by eight (signed) cmp #128 bcc div8cc ; Value in Acc less than 128 adc #$02 ; Carry is set, so we're adding 3 bcs div8ccnr lsr lsr lsr ora #$E0 rts div8cc: adc #4 div8ccnr: lsr lsr lsr rts Perhaps not quite optimal, but it should yield symmetrically-rounded results. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 i used the ASL simply because of this: -1 = 255 -2 = 254 -4 = 252 so i am shifting to the left? Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted July 20, 2005 Share Posted July 20, 2005 Hi there! i used the ASL simply because of this: -1 = 255 -2 = 254 -4 = 252 so i am shifting to the left? 894856[/snapback] Uhm... what, why left ? -1 = 255 = 11111111 -2 = 254 = 11111110 -4 = 252 = 11111100 Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 20, 2005 Share Posted July 20, 2005 -1 = 255 = 11111111-2 = 254 = 11111110 -4 = 252 = 11111100 Ähm, das IST links, Manuel. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 danke. thomas für den hinweis... but am i right? Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted July 20, 2005 Share Posted July 20, 2005 Huhu! -1 = 255 = 11111111-2 = 254 = 11111110 -4 = 252 = 11111100 Ähm, das IST links, Manuel. 894889[/snapback] Öhm... schlaft ihr heute alle, oder was? Um von -4 auf -2 zu kommen, muss man nach rechts schieben (SEC + ROR um genau zu sein) und das Ganze nennt sich dann Division durch 2. Grüße, Manuel Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 20, 2005 Share Posted July 20, 2005 Öhm... schlaft ihr heute alle, oder was? Um von -4 auf -2 zu kommen, muss man nach rechts schieben (SEC + ROR um genau zu sein) und das Ganze nennt sich dann Division durch 2. Ach soooo. Ich hatte übersehen, dass du seit Neuestem von unten nach oben liest. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 aber manuel, dann erklär mir bitte für mich nicht mathematiker, mein beispiel mit den -60........ player position =100 enemy position =160 ... Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 20, 2005 Share Posted July 20, 2005 (edited) 100 - 160 = -60 = $c4 (bzw. $ffc4) Teilen durch 8: 3 x lsr (und dabei jeweils das Vorzeichen-Bit in's MSB kopieren) = $f8 (bzw. $fff8) = -8 ; 8 bit math lda px sec sbc ex cmp #$80 ror cmp #$80 ror cmp #$80 ror Edited July 20, 2005 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 strange code... but this is the difference between demo coders and professional coders... i'll take the code from thomas and will not try to understand it... Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted July 20, 2005 Share Posted July 20, 2005 (edited) 100 - 160 = -60 = $c4 (bzw. $ffc4) Teilen durch 8: 3 x lsr (und dabei jeweils das Vorzeichen-Bit in's MSB kopieren) = $f8 (bzw. $fff8) = -8 ; 8 bit math lda px sec sbc ex cmp #$80 ror cmp #$80 ror cmp #$80 ror 894941[/snapback] Can I get a translation, please? This looks interesting... EDIT: Actually, I think I got it - the cmp #$80 ror sequence divides a number of either sign by 2 and preserves the sign: -100 -> -50 or 64 -> 32. Right? And tricksy, it is... Edited July 20, 2005 by vdub_bobby Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 btw. just tested the code... it works... Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted July 20, 2005 Share Posted July 20, 2005 btw. just tested the code... it works... 895284[/snapback] Not for -1, I don't think: lda #-1 cmp #$80 ror A holds -1, not zero. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 20, 2005 Share Posted July 20, 2005 That's a rounding problem. Quote Link to comment Share on other sites More sharing options...
+batari Posted July 20, 2005 Share Posted July 20, 2005 Can I get a translation, please? This looks interesting... 895281[/snapback] http://translate.google.com/translate?u=ht...Flanguage_tools Ach du lieber! Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted July 20, 2005 Share Posted July 20, 2005 Can I get a translation, please? This looks interesting... 895281[/snapback] http://translate.google.com/translate?u=ht...Flanguage_tools Ach du lieber! 895293[/snapback] Ummm...thanks, I guess. Best translation was this: Ach soooo. Ich hatte übersehen, dass du seit Neuestem von unten nach oben liest. To this: Oh soooo. I had surveyed that you since newest one from down upward reads. That's a rounding problem. I'm just saying is all. It's a slick routine, it just won't take a negative number to zero. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 20, 2005 Author Share Posted July 20, 2005 here is the atari800 code in xasm format: * Enemy Engine - Test * pmbase equ $8000 p0 equ $8400 org $4000 init ldx #3 init0 lda 53770 sta ex,x lda 53770 sta ey,x lda #0 sta 53256,x lda #15 sta 704,x dex bpl init0 lda #>pmbase sta 54279 lda #3 sta 53277 ldx #0 txa init1 sta p0,x sta p0+256,x sta p0+512,x sta p0+758,x inx bne init1 lda #62 sta 559 lda #8 sta 704 lda py sta oldpy lda ey sta oldey main_loop jsr wait_vbl jsr calc jsr get_stick jsr set_pm inc count bpl main_loop lda #0 sta count lda 53770 ;random sta ex lda 53770 sta ey jmp main_loop wait_vbl lda #1 sta 540 wait0 lda 540 bne wait0 rts set_pm lda #0 ldx oldpy ldy #7 clear0 sta p0,x inx dey bpl clear0 ldx oldey ldy #7 clear1 sta p0+256,x inx dey bpl clear1 lda py sta oldpy lda ey sta oldey ldy #7 ldx py lda px sta 53248 ;hposp0 set0 lda shape0,y sta p0,x inx dey bpl set0 ldy #7 ldx ey lda ex sta 53249 ;hposp1 set1 lda shape1,y sta p0+256,x inx dey bpl set1 rts ;* Joystick routine get_stick lda 632 ;stick0 tay get_stick1 and #$f8 ;right? beq stick_r tya get_stick2 and #244 ;left? beq stick_l get_stick0 tya get_stick3 and #241 ;up? beq stick_u tya get_stick4 and #242 ;down? beq stick_d joy_end rts stick_r inc px rts stick_l dec px rts stick_u dec py rts stick_d inc py rts * vex=(px-ex)/16 * vey=(py-ey)/16 * ex=ex+vex * ey=ey+vey calc lda px sec sbc ex cmp #$80 ror @ cmp #$80 ror @ cmp #$80 ror @ cmp #$80 ror @ clc adc ex sta ex lda py sec sbc ey cmp #$80 ror @ cmp #$80 ror @ cmp #$80 ror @ clc adc ey sta ey rts shape0 dta %00000000 dta %01111110 dta %01111110 dta %01111110 dta %01111110 dta %01111110 dta %01111110 dta %00000000 shape1 dta %00000000 dta %10000001 dta %01000010 dta %00100100 dta %00011000 dta %00011000 dta %00000000 dta %00000000 vex dta 0,0,0,0 vey dta 0,0,0,0 ex dta 0,0,0,0 ey dta 0,0,0,0 px dta 100 py dta 100 oldpy dta 0 oldey dta 0 count dta 0 run init should be understandable... Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 21, 2005 Author Share Posted July 21, 2005 thomas... your 8bit version seems too fast when moving objects around...the player seems not to have a chance to escape (check it on yourself in a 2600 prototype). so i guess we need 4.4 or 8.8 fixed point maths...what do you think? and if so...how would you handle that in your code? (i just woke up so my 6502 knowledge is not booted yet... ) Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 21, 2005 Share Posted July 21, 2005 thomas... your 8bit version seems too fast when moving objects around... Huh? How can the code be too fast? so i guess we need 4.4 or 8.8 fixed point maths...what do you think? and if so...how would you handle that in your code? (i just woke up so my 6502 knowledge is not booted yet... ) If 4.4 doesn't do the job, try something like 3.5 or 2.6. Or switch to 8.8 which is pretty easy to implement. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 21, 2005 Author Share Posted July 21, 2005 re: fast... try to put the code into a 2600 kernel and you know what i mean... i am doing a random repositioning of the player every 16 VBLs. every slower repositioning leads to that the enemy is catching the player in miliseconds... of course i could do a slower moving of the enemy, f.e. every 25th second or 12... (2nd/3rd frame) but this looks strange and not very professional... so i guess i have to go with 4.4 as next try. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 21, 2005 Share Posted July 21, 2005 (edited) try to put the code into a 2600 kernel and you know what i mean... Sorry, but I am completely lost. What do you mean? Which kernel? Which enemies? How are they moving (I must have missed something ) BTW: What are VBLs? vertical blanks = frames? Edited July 21, 2005 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted July 21, 2005 Author Share Posted July 21, 2005 thomas, i mean you are a wizard and should be able to code a simple 2600 demo with the formulars i have described. one random position where an enemy sprite is moving to. you can do it simply on 2600 as well... then you are realising that the enemy is moving very very fast towards the desired position... in german: was ich meinte, da dir 2600 so am herzen liegt, solltest du doch sehr schnell eine mini-demo auf 2600 basis machen können, um dieses tracking der feinde anhand eines player-sprites zu testen... (oder kannste auch auf 800??? ) das meinte ich, das enemy sprite fliegt zuuu schnell auf den spieler zu, zwar korrekt aber definitiv zu schnell... und das liegt meiner meinung nach an der fehlenden genauigkeit und den rundungen. daher meine idee der fixed point math. eine verlangsamung durch d.h. bewegen alle 2. oder 3. VBI/frame sieht kacke aus... Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted July 21, 2005 Share Posted July 21, 2005 It looks to me like you are taking the difference between the enemy position and the player position, dividing that by 8, and adding it to the enemy position. Depending on how often you run the routine, that will be impossibly fast - using some kind of fractional position (8.8 fixed would probably be easiest) is probably a necessity. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 21, 2005 Share Posted July 21, 2005 thomas, i mean you are a wizard and should be able to code a simple 2600 demo with the formulars i have described. one random position where an enemy sprite is moving to. you can do it simply on 2600 as well... then you are realising that the enemy is moving very very fast towards the desired position... Ok, now I understand. I suggest to use 8.8 maths for position and speed. 4 bytes for x and y each. If the maximum speed is smaller than 0.5 pixel/frame, then you only need 3 bytes each. Then for the movement you could simply do: lda xSpeedLo clc adc xPosLo sta xPosLo lda xSpeedHi adc xPosHi sta xPosHi Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.