Heaven/TQA Posted August 14, 2005 Share Posted August 14, 2005 again i need help for my game Boinxx... and again it's math... as memory is getting tight is there any very fast way of performing a div 10 and div 6? i need that for checking which tile lies under the player... and as the screen is 40 bytes large and holds 10 tiles (4x4 ones) i want to avoid lookup tables but want to get the tile no. directly from the player sprite position... so for the xposition i would perform this (simplified...): tile=tile_buffer[hposp0/10+10*(ypos/6)] oh... very uncommon values 10,6... maybe i sould spend 512 bytes for the lookup tables... but if there is a realtime fast way any hint much appreciated. i have attachted the binary to get a view (load the .obx file like any other game...i suggest atari800win beta 6: http://atariarea.histeria.pl/PLus/index_us.htm) Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted August 14, 2005 Author Share Posted August 14, 2005 here is the binary boinxx7a.zip Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted August 14, 2005 Share Posted August 14, 2005 Divide by 8 and then use a table. Quote Link to comment Share on other sites More sharing options...
Bruce Tomlin Posted August 14, 2005 Share Posted August 14, 2005 Use the trusty subtract and count method. It's a tradeoff between cycles and space, and with the highest number you're dividing being 40, there it won't take many cycles. Of course if the biggest number you're dividing is really 39, then that would be 80 bytes for tables, not 512. That's still larger than a couple of hardcoded subtract and count subroutines. Quote Link to comment Share on other sites More sharing options...
Alex H Posted August 14, 2005 Share Posted August 14, 2005 ; divide value in temp by 10 lda temp lsr lsr clc adc temp lsr clc adc temp lsr lsr lsr clc adc temp lsr clc adc temp lsr lsr lsr lsr sta temp I think that's right. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted August 14, 2005 Share Posted August 14, 2005 Hi there! Of course if the biggest number you're dividing is really 39, then that would be 80 bytes for tables 40 bytes when doing a LSR first... Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted August 14, 2005 Author Share Posted August 14, 2005 thanks! but as it's done via VBL i might use a lookup table...haven't thought of using pre-LSR so i can squeeze the tables into 256 bytes... on a 64kram machine should be good enough... ;=) Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted August 15, 2005 Share Posted August 15, 2005 (edited) thanks! but as it's done via VBL i might use a lookup table...haven't thought of using pre-LSR so i can squeeze the tables into 256 bytes...on a 64kram machine should be good enough... ;=) 911275[/snapback] As I described above your can do 2 (div 6) or 3 (div 8 ) LSRs before table lookup. Edited August 15, 2005 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Robert M Posted August 17, 2005 Share Posted August 17, 2005 again i need help for my game Boinxx... and again it's math... as memory is getting tight is there any very fast way of performing a div 10 and div 6? tile=tile_buffer[hposp0/10+10*(ypos/6)] That formula does not seem right to me. Shouldn't it be: tile_num = xpos/TILE_WIDTH + NUM_TILES_ACROSS * (ypos/TILE HEIGHT) IF you make TILE_WIDTH and TILE_HEIGHT powers of 2 then you can do quick divide by shift operations. GIVEN: TILE_WIDTH = TILE_HEIGHT = 16 X = xpos and Y = ypos THEN CalcTile TYA AND #%11110000; Mask out fractional bits to optimize *10 LSR STA temp; Save (ypos/width) * 8 LSR LSR ;; CLC ; CLC not needed ADC temp; (ypos/height) * 8 + (ypos/height)*2 = 10 * (ypos/height) STA temp TXA LSR LSR LSR LSR ; xpos /16 CLC ADC temp; tile_num = (xpos/width) + 10 * (ypos/height) Also if you invert the matrix storage in memory so that its like this: tile_num = ypos/TILE_HEIGHT + NUM_TILES_DOWN * (xpos/TILE_WIDTH) then you can set NUM_TILES_DOWN to 8 and simply use 6 entries in each column of tile_buffer to hold the game board, but use 2 entires to hold something else and optimize the code like this: GIVEN: tile_num = ypos/TILE_HEIGHT + NUM_TILES_DOWN * (xpos/TILE_WIDTH) TILE_HEIGHT = 16 TILE_WIDTH = 16 NUM_TILES_DOWN = 8; really 6, but we are going to not use 2 rows Y = ypos, X = xpos THEN calctile TXA AND #%11110000 LSR ; NUM_TILES_DOWN * (xpos/TILE_WIDTH), where TILE_WIDTH = 16 STA temp TYA LSR ; divide by tile height LSR LSR LSR ORA temp ; tile_num = ypos/TILE_HEIGHT + NUM_TILES_DOWN * (xpos/TILE_WIDTH) ; Also the tile_buffer is arranges in memory as tile_buffer column0 DS.b 6; Allocate 6 bytes for the first column. DS.b 2; These 2 bytes are free to be used for anything else. column1 DS.b 6; Allocate 6 bytes for the second column. DS.b 2; These 2 bytes are free to be used for anything else. column2 DS.b 6; Allocate 6 bytes for the third column. DS.b 2; These 2 bytes are free to be used for anything else. column3 DS.b 6; Allocate 6 bytes for the fourth column. DS.b 2; These 2 bytes are free to be used for anything else. column4 DS.b 6; Allocate 6 bytes for the fifth column. DS.b 2; These 2 bytes are free to be used for anything else. column5 DS.b 6; Allocate 6 bytes for the sixth column. DS.b 2; These 2 bytes are free to be used for anything else. column6 DS.b 6; Allocate 6 bytes for the seventh column. DS.b 2; These 2 bytes are free to be used for anything else. column7 DS.b 6; Allocate 6 bytes for the eigth column. DS.b 2; These 2 bytes are free to be used for anything else column8 DS.b 6; Allocate 6 bytes for the ninth column. DS.b 2; These 2 bytes are free to be used for anything else. column9 DS.b 6; Allocate 6 bytes for the tenth column. DS.b 2; These 2 bytes are free to be used for anything else. 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.