; Zilog eZ80 ANSI C Compiler Release 3.4 ; -optsize -noreduceopt -nomodsect -peephole -globalopt ; -localcse -const=ROM FILE "SRC\MAIN.C" .assume ADL=1 SEGMENT BSS _key: DS 1 SEGMENT DATA _speed: DF 0.5 SEGMENT BSS _i: DS 3 _bulletSpawned: DS 3 _baddieSpawned: DS 3 SEGMENT DATA _gameloop: DW 0 DB 0 SEGMENT BSS _player: DS 16 SEGMENT CODE _updatePlayer: LD HL,-3 CALL __frameset LD BC,_player LD (IX+-3),BC LD HL,(IX+6) LD E,(IX+9) LD IY,(IX+-3) LD BC,(IY+0) LD A,(IY+3) CALL __fadd LD (IY+0),BC LD (IY+3),A LD HL,(IX+12) LD E,(IX+15) LD BC,(IY+4) LD A,(IY+7) CALL __fadd LD (IY+4),BC LD (IY+7),A LD SP,IX POP IX RET ;**************************** _updatePlayer *************************** ;Name Addr/Register Size Type ;_player STATIC 16 variable ;dy IX+12 4 parameter ;dx IX+6 4 parameter ; Stack Frame Size: 21 (bytes) ; Spill Code: 0 (instruction) SEGMENT BSS _bullets: DS 45 SEGMENT CODE _spawnBullet: LD HL,-6 CALL __frameset LD BC,1 LD HL,(_gameloop) OR A,A SBC HL,BC JR NZ,L_8 LD BC,0 LD (_i),BC JR L_5 L_3: LD HL,(_i) LD A,9 CALL __imul_b LD (IX+-3),HL LD BC,_bullets ADD HL,BC LD IY,HL LD A,(IY+0) CP A,1 JR NZ,L_4 LD HL,(IX+-3) ADD HL,BC LD (IX+-6),HL LD BC,(IX+6) LD A,(IX+9) LD IY,(IX+-6) LD (IY+1),BC LD (IY+4),A LD BC,(IX+12) LD A,(IX+15) LD (IY+5),BC LD (IY+8),A LD (IY+0),0 LD HL,1 JR L_9 L_4: LD BC,(_i) INC BC LD (_i),BC L_5: LD BC,5 LD HL,(_i) OR A,A SBC HL,BC CALL __setflag JP M,L_3 LD HL,1 JR L_9 L_8: OR A,A SBC HL,HL L_9: LD SP,IX POP IX RET ;**************************** _spawnBullet *************************** ;Name Addr/Register Size Type ;_bullets STATIC 45 variable ;_i STATIC 3 variable ;_gameloop STATIC 3 variable ;G_0 IX-3 3 variable ;posY IX+12 4 parameter ;posX IX+6 4 parameter ; Stack Frame Size: 24 (bytes) ; Spill Code: 0 (instruction) _updateBullets: LD HL,-12 CALL __frameset LD BC,0 LD (_i),BC JR L_16 L_14: LD HL,(_i) LD A,9 CALL __imul_b LD (IX+-3),HL LD BC,_bullets ADD HL,BC LD (IX+-6),HL LD IY,(IX+-6) LD A,(IY+0) OR A,A JR NZ,L_15 LD IY,(IX+-6) LD HL,(IY+1) LD E,(IY+4) LD BC,11010048 LD A,67 CALL __fcmp JP P,L_12 LD BC,_bullets LD HL,(IX+-3) ADD HL,BC LD (IX+-12),HL LD IY,(IX+-12) LEA BC,IY+1 LD (IX+-9),BC LD HL,(_speed) LD A,(_speed+3) LD IY,(IX+-9) LD BC,(IY+0) LD E,A LD A,(IY+3) CALL __fadd LD (IY+0),BC LD (IY+3),A LD BC,(IY+4) LD A,(IY+7) CALL __ftol PUSH BC LD BC,(IY+0) LD A,(IY+3) CALL __ftol PUSH BC LD BC,_bullet_data PUSH BC CALL _gfx_Sprite POP BC POP BC POP BC JR L_15 L_12: LD IY,(IX+-6) LD (IY+0),1 L_15: LD BC,(_i) INC BC LD (_i),BC L_16: LD BC,45 LD HL,(_i) OR A,A SBC HL,BC JR C,L_14 LD SP,IX POP IX RET ;**************************** _updateBullets *************************** ;Name Addr/Register Size Type ;_bullet_data IMPORT 258 variable ;_gfx_Sprite IMPORT ----- function ;_speed STATIC 4 variable ;_bullets STATIC 45 variable ;_i STATIC 3 variable ;G_1 IX-6 3 variable ;G_2 IX-3 3 variable ; Stack Frame Size: 18 (bytes) ; Spill Code: 0 (instruction) SEGMENT BSS _baddies: DS 288 SEGMENT CODE ; 1 // Libraries lol ; 2 #include ; 3 #include ; 4 #include ; 5 #include ; 6 #include ; 7 #include ; 8 #include ; 9 #include ; 10 #include ; 11 #include ; 12 #include ; 13 ; 14 // Graphics ; 15 #include "gfx/sprites.h" ; 16 ; 17 // set global vars ; 18 kb_key_t key; ; 19 float speed = 0.5; ; 20 int i; ; 21 int bulletSpawned; ; 22 int baddieSpawned; ; 23 int gameloop = 0; ; 24 ; 25 // Include entity headers ; 26 #include "player.h" ; 27 #include "bullet.h" ; 28 #include "baddie.h" ; 29 ; 30 void setup() { _setup: LD HL,-9 CALL __frameset ; 31 boot_Set48MHzModeI(); CALL _boot_Set48MHzModeI ; 32 ; 33 /* Initialize the 8bpp graphics */ ; 34 gfx_Begin(); CALL _gfx_Begin ; 35 dbg_sprintf(dbgout, "This is the start of a CEmu debugging test\n"); ; 36 dbg_Debugger(); ; 37 ; 38 /* Set up the palette for our sprites */ ; 39 gfx_SetPalette(sprites_pal, sizeof_sprites_pal, 0); LD BC,0 PUSH BC LD BC,18 PUSH BC LD BC,_sprites_pal PUSH BC CALL _gfx_SetPalette POP BC POP BC POP BC ; 40 ; 41 // Clear screen ; 42 gfx_FillScreen(02); LD BC,2 PUSH BC CALL _gfx_FillScreen POP BC ; 43 ; 44 // Player starting position ; 45 player.pos.x = 10; LD BC,_player LD (IX+-6),BC LD IY,(IX+-6) LD BC,2097152 LD (IY+0),BC LD A,65 LD (IY+3),A ; 46 player.pos.y = 136; LD BC,524288 LD (IY+4),BC LD (IY+7),67 ; 47 player.oldPos.x = 10; LD BC,_player+8 LD (IX+-3),BC LD IY,(IX+-3) LD BC,2097152 LD (IY+0),BC LD (IY+3),A ; 48 player.oldPos.y = 10; LD (IY+4),BC LD (IY+7),A ; 49 ; 50 // Reset all bullets ; 51 for (i = 0; i < 5; i++) LD BC,0 LD (_i),BC JR L_23 L_21: ; 52 { ; 53 bullets[i].dead = true; LD HL,(_i) LD A,9 CALL __imul_b LD BC,_bullets ADD HL,BC LD (IX+-9),HL LD IY,(IX+-9) LD (IY+0),1 ; 54 bullets[i].pos.x = 0; LD BC,0 LD (IY+1),BC LD (IY+4),0 ; 55 bullets[i].pos.y = 0; LD (IY+5),BC LD (IY+8),0 LD BC,(_i) INC BC LD (_i),BC ; 56 } L_23: LD BC,5 LD HL,(_i) OR A,A SBC HL,BC JP M,L_21 ; 57 } LD SP,IX POP IX RET ;**************************** _setup *************************** ;Name Addr/Register Size Type ;_bullets STATIC 45 variable ;_i STATIC 3 variable ;_player STATIC 16 variable ;_gfx_FillScreen IMPORT ----- function ;_sprites_pal IMPORT 18 variable ;_gfx_SetPalette IMPORT ----- function ;_gfx_Begin IMPORT ----- function ;_boot_Set48MHzModeI IMPORT ----- function ; Stack Frame Size: 15 (bytes) ; Spill Code: 0 (instruction) ; 58 ; 59 void main(void) { _main: LD HL,-39 CALL __frameset ; 60 setup(); CALL _setup ; 61 gameloop = 1; LD BC,1 LD (_gameloop),BC ; 62 do { L_45: ; 63 // Scan keyboard for button presses ; 64 kb_Scan(); CALL _kb_Scan ; 65 ; 66 // Move all alive bullets ; 67 updateBullets(); CALL _updateBullets ; 68 ; 69 // set key to keyboard memory adress row 7 ; 70 key = kb_Data[7]; LD A,(16056350) LD (_key),A ; 71 ; 72 // Move player ; 73 //// Down ; 74 if (key & kb_Down) { AND A,1 JR Z,L_29 ; 75 if (!(player.pos.y >= (LCD_HEIGHT - 32))) { LD BC,_player LD (IX+-21),BC LD IY,(IX+-21) LD HL,(IY+4) LD E,(IY+7) LD BC,5242880 LD A,67 CALL __fcmp JP P,L_29 ; 76 player.pos.y += speed; LD HL,(_speed) LD A,(_speed+3) LD IY,(IX+-21) LD BC,(IY+4) LD E,A LD A,(IY+7) CALL __fadd LD (IY+4),BC LD (IY+7),A ; 77 } ; 78 } L_29: ; 79 //// Up ; 80 if (key & kb_Up) { LD A,(_key) AND A,8 JR Z,L_32 ; 81 if (!(player.pos.y <= 0)) { LD BC,_player LD (IX+-6),BC LD IY,(IX+-6) LD BC,(IY+4) LD A,(IY+7) OR A,A SBC HL,HL LD E,0 CALL __fcmp JP P,L_32 ; 82 player.pos.y -= speed; LD HL,(_speed) LD A,(_speed+3) LD IY,(IX+-6) LD BC,(IY+4) LD E,A LD A,(IY+7) CALL __fsub LD (IY+4),BC LD (IY+7),A ; 83 } ; 84 } L_32: ; 85 //// Left ; 86 if (key & kb_Left) { LD A,(_key) AND A,2 JR Z,L_35 ; 87 if (!(player.pos.x <= 0)) { LD BC,_player LD (IX+-9),BC LD IY,(IX+-9) LD BC,(IY+0) LD A,(IY+3) OR A,A SBC HL,HL LD E,0 CALL __fcmp JP P,L_35 ; 88 player.pos.x -= speed; LD HL,(_speed) LD A,(_speed+3) LD IY,(IX+-9) LD BC,(IY+0) LD E,A LD A,(IY+3) CALL __fsub LD (IY+0),BC LD (IY+3),A ; 89 } ; 90 } L_35: ; 91 //// Right ; 92 if (key & kb_Right) { LD A,(_key) AND A,4 JR Z,L_38 ; 93 if (!(player.pos.x >= (LCD_WIDTH - 32))) { LD BC,_player LD (IX+-12),BC LD IY,(IX+-12) LD HL,(IY+0) LD E,(IY+3) LD BC,9437184 LD A,67 CALL __fcmp JP P,L_38 ; 94 player.pos.x += speed; LD HL,(_speed) LD A,(_speed+3) LD IY,(IX+-12) LD BC,(IY+0) LD E,A LD A,(IY+3) CALL __fadd LD (IY+0),BC LD (IY+3),A ; 95 } ; 96 } L_38: ; 97 ; 98 // Spawn bullet on 2nd press ; 99 if (kb_Data[1] & kb_2nd) { LD A,(16056338) AND A,32 JR Z,L_40 ; 100 // If bullet has already been spawned (You cannot hold the button) ; 101 if (bulletSpawned == 0){ LD HL,(_bulletSpawned) CALL __icmpzero JR NZ,L_40 ; 102 spawnBullet((player.pos.x + 16), (player.pos.y + 8)); LD BC,_player LD (IX+-30),BC LD IY,(IX+-30) LD BC,(IY+4) LD A,(IY+7) OR A,A SBC HL,HL LD E,65 CALL __fadd LD (IX+-39),BC ; spill LD C,A LD HL,8388608 LD E,65 LD B,0 PUSH BC LD (IX+-36),HL ; spill LD HL,(IX+-39) ; unspill PUSH HL LD HL,(IX+-36) ; unspill LD BC,(IY+0) LD A,(IY+3) CALL __fadd LD DE,BC LD C,A LD B,0 PUSH BC PUSH DE CALL _spawnBullet POP BC POP BC POP BC POP BC ; 103 bulletSpawned = 1; LD BC,1 LD (_bulletSpawned),BC ; 104 } ; 105 } L_40: ; 106 ; 107 // Set bulletSpawned to false if button is let loose ; 108 if (kb_Data[1] != kb_2nd){ LD A,(16056338) CP A,32 JR Z,L_44 ; 109 bulletSpawned = 0; LD BC,0 LD (_bulletSpawned),BC ; 110 } L_44: ; 111 ; 112 // Redraw all sprites if player pos has changed or a bullet has been spawned ; 113 if ( (abs(player.oldPos.x - player.pos.x) >= 1) || (abs(player.oldPos.y - player.pos.y) >= 1) || bulletSpawned == 1) { LD BC,_player+8 LD (IX+-18),BC LD BC,_player LD (IX+-15),BC LD (IX+-24),BC LD BC,(IX+-18) LD (IX+-27),BC LD IY,(IX+-15) LD HL,(IY+0) LD E,(IY+3) LD IY,(IX+-18) LD BC,(IY+0) LD A,(IY+3) CALL __fsub CALL __ftol PUSH BC CALL _abs POP BC LD BC,1 OR A,A SBC HL,BC JP P,L_43 LD BC,(IX+-15) LD (IX+-24),BC LD BC,(IX+-18) LD (IX+-27),BC LD IY,(IX+-15) LD HL,(IY+4) LD E,(IY+7) LD IY,(IX+-18) LD BC,(IY+4) LD A,(IY+7) CALL __fsub CALL __ftol PUSH BC CALL _abs POP BC LD BC,1 OR A,A SBC HL,BC CALL __setflag JP P,L_43 LD HL,(_bulletSpawned) OR A,A SBC HL,BC JR NZ,L_46 L_43: ; 114 gfx_Sprite(spaceship, player.pos.x, player.pos.y); LD BC,(IX+-24) LD (IX+-3),BC LD IY,(IX+-3) LD BC,(IY+4) LD A,(IY+7) CALL __ftol PUSH BC LD BC,(IY+0) LD A,(IY+3) CALL __ftol PUSH BC LD BC,_spaceship_data PUSH BC CALL _gfx_Sprite POP BC POP BC POP BC ; 115 player.oldPos.x = player.pos.x; LD BC,(IX+-27) LD (IX+-33),BC LD IY,(IX+-3) LD BC,(IY+0) LD A,(IY+3) LD IY,(IX+-33) LD (IY+0),BC LD (IY+3),A ; 116 player.oldPos.y = player.pos.y; LD IY,(IX+-3) LD BC,(IY+4) LD A,(IY+7) LD IY,(IX+-33) LD (IY+4),BC LD (IY+7),A ; 117 } ; 118 } while (kb_Data[6] != kb_Enter); L_46: LD A,(16056348) CP A,1 JR NZ,L_45 ; 119 ; 120 // Close the graphics ; 121 gfx_End(); CALL _gfx_End LD SP,IX POP IX RET ;**************************** _main *************************** ;Name Addr/Register Size Type ;_gfx_End IMPORT ----- function ;_spaceship_data IMPORT 1026 variable ;_gfx_Sprite IMPORT ----- function ;_abs IMPORT ----- function ;_bulletSpawned STATIC 3 variable ;_speed STATIC 4 variable ;_player STATIC 16 variable ;_key STATIC 1 variable ;_kb_Scan IMPORT ----- function ;_gameloop STATIC 3 variable ;G_12 IX-27 3 variable ;G_10 IX-24 3 variable ;G_4 IX-21 3 variable ;G_8 IX-18 3 variable ;G_9 IX-15 3 variable ;G_7 IX-12 3 variable ;G_6 IX-9 3 variable ;G_5 IX-6 3 variable ;G_11 IX-3 3 variable ; Stack Frame Size: 45 (bytes) ; Spill Code: 0 (instruction) XREF _sprites_pal:ROM XREF _bullet_data:ROM XREF _spaceship_data:ROM XREF _kb_Scan:ROM XREF _gfx_Sprite:ROM XREF _gfx_FillScreen:ROM XREF _gfx_SetPalette:ROM XREF _gfx_End:ROM XREF _gfx_Begin:ROM XREF _abs:ROM XREF _boot_Set48MHzModeI:ROM XREF __fadd:ROM XREF __fsub:ROM XREF __fcmp:ROM XREF __ftol:ROM XREF __frameset:ROM XREF __setflag:ROM XREF __icmpzero:ROM XREF __imul_b:ROM XDEF _main XDEF _setup XDEF _baddies XDEF _updateBullets XDEF _spawnBullet XDEF _bullets XDEF _updatePlayer XDEF _player XDEF _gameloop XDEF _baddieSpawned XDEF _bulletSpawned XDEF _i XDEF _speed XDEF _key END