gb_test2
annotate test.asm @ 0:cacfa0888410
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 10 Jan 2019 04:16:47 +0200 |
parents | |
children | d63782badb6b |
rev | line source |
---|---|
nuclear@0 | 1 ; vi:ft=rgbasm: |
nuclear@0 | 2 include "hw.inc" |
nuclear@0 | 3 |
nuclear@0 | 4 xoffs_center equ 4 |
nuclear@0 | 5 yoffs_center equ 12 |
nuclear@0 | 6 |
nuclear@0 | 7 frame_ptr equ $ff80 |
nuclear@0 | 8 |
nuclear@0 | 9 section "hdr", ROM0[$100] |
nuclear@0 | 10 nop |
nuclear@0 | 11 jp main |
nuclear@0 | 12 |
nuclear@0 | 13 rept $150 - $104 |
nuclear@0 | 14 db 0 |
nuclear@0 | 15 endr |
nuclear@0 | 16 |
nuclear@0 | 17 section "text", ROM0 |
nuclear@0 | 18 |
nuclear@0 | 19 main: |
nuclear@0 | 20 call init |
nuclear@0 | 21 |
nuclear@0 | 22 xor a, a |
nuclear@0 | 23 ldh [frame_ptr], a |
nuclear@0 | 24 .mainloop: |
nuclear@0 | 25 ldh a, [REG_LY] |
nuclear@0 | 26 cp a, 144 |
nuclear@0 | 27 jr c, .wait_hsync |
nuclear@0 | 28 |
nuclear@0 | 29 ; we're in vsync, increment frame counter and wait for the next frame |
nuclear@0 | 30 ldh a, [frame_ptr] |
nuclear@0 | 31 inc a |
nuclear@0 | 32 ldh [frame_ptr], a |
nuclear@0 | 33 .wait_newframe: |
nuclear@0 | 34 ldh a, [REG_LY] |
nuclear@0 | 35 cp a, 0 |
nuclear@0 | 36 jr nz, .wait_newframe |
nuclear@0 | 37 |
nuclear@0 | 38 ; scanline code |
nuclear@0 | 39 .wait_hsync: |
nuclear@0 | 40 ldh a, [REG_STAT] |
nuclear@0 | 41 and a, STAT_MODE_MASK |
nuclear@0 | 42 jr nz, .wait_hsync |
nuclear@0 | 43 |
nuclear@0 | 44 ldh a, [frame_ptr] |
nuclear@0 | 45 ld d, a |
nuclear@0 | 46 |
nuclear@0 | 47 xor a, a |
nuclear@0 | 48 ld b, a |
nuclear@0 | 49 ldh a, [REG_LY] |
nuclear@0 | 50 add a, d |
nuclear@0 | 51 ld c, a |
nuclear@0 | 52 |
nuclear@0 | 53 ld hl, sintab |
nuclear@0 | 54 add hl, bc ; hl points to sin value (0-64) |
nuclear@0 | 55 |
nuclear@0 | 56 ld a, yoffs_center |
nuclear@0 | 57 add a, [hl] |
nuclear@0 | 58 ldh [REG_SCY], a |
nuclear@0 | 59 |
nuclear@0 | 60 ; done, wait until we're out of hsync |
nuclear@0 | 61 .wait_endhsync: |
nuclear@0 | 62 ldh a, [REG_STAT] |
nuclear@0 | 63 and a, STAT_MODE_MASK |
nuclear@0 | 64 jr z, .wait_endhsync |
nuclear@0 | 65 |
nuclear@0 | 66 jr .mainloop |
nuclear@0 | 67 |
nuclear@0 | 68 |
nuclear@0 | 69 di |
nuclear@0 | 70 .end: halt |
nuclear@0 | 71 nop |
nuclear@0 | 72 jp .end |
nuclear@0 | 73 |
nuclear@0 | 74 init: |
nuclear@0 | 75 call wait_vsync |
nuclear@0 | 76 xor a, a |
nuclear@0 | 77 ldh [REG_LCDC], a |
nuclear@0 | 78 |
nuclear@0 | 79 ; setup identity palette |
nuclear@0 | 80 ld a, $1b |
nuclear@0 | 81 ldh [REG_BGP], a |
nuclear@0 | 82 |
nuclear@0 | 83 |
nuclear@0 | 84 ; copy tiles |
nuclear@0 | 85 ld hl, $8000 |
nuclear@0 | 86 ld de, tiles |
nuclear@0 | 87 ld bc, tiles_end - tiles |
nuclear@0 | 88 .copytiles: |
nuclear@0 | 89 ld a, [de] |
nuclear@0 | 90 ld [hl+], a |
nuclear@0 | 91 inc de |
nuclear@0 | 92 dec bc |
nuclear@0 | 93 ld a, b |
nuclear@0 | 94 or c |
nuclear@0 | 95 jp nz, .copytiles |
nuclear@0 | 96 |
nuclear@0 | 97 ; copy tilemap |
nuclear@0 | 98 ld hl, $9800 |
nuclear@0 | 99 ld de, tilemap |
nuclear@0 | 100 ld b, 21 |
nuclear@0 | 101 .copymap: |
nuclear@0 | 102 ld c, 21 |
nuclear@0 | 103 .copymaprow: |
nuclear@0 | 104 ld a, [de] |
nuclear@0 | 105 inc de |
nuclear@0 | 106 ld [hl+], a |
nuclear@0 | 107 dec c |
nuclear@0 | 108 jr nz, .copymaprow |
nuclear@0 | 109 |
nuclear@0 | 110 push bc |
nuclear@0 | 111 ld bc, 11 |
nuclear@0 | 112 add hl, bc |
nuclear@0 | 113 pop bc |
nuclear@0 | 114 |
nuclear@0 | 115 dec b |
nuclear@0 | 116 jr nz, .copymap |
nuclear@0 | 117 |
nuclear@0 | 118 ; center viewport |
nuclear@0 | 119 ld a, yoffs_center |
nuclear@0 | 120 ldh [REG_SCY], a |
nuclear@0 | 121 ld a, xoffs_center |
nuclear@0 | 122 ldh [REG_SCX], a |
nuclear@0 | 123 |
nuclear@0 | 124 ; configure LCD |
nuclear@0 | 125 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON |
nuclear@0 | 126 ldh [REG_LCDC], a |
nuclear@0 | 127 ret |
nuclear@0 | 128 |
nuclear@0 | 129 wait_vsync: |
nuclear@0 | 130 ldh a, [REG_LY] |
nuclear@0 | 131 cp a, 144 |
nuclear@0 | 132 jr c, wait_vsync |
nuclear@0 | 133 ret |
nuclear@0 | 134 |
nuclear@0 | 135 section "data", ROM0, align[8] |
nuclear@0 | 136 sintab: |
nuclear@0 | 137 include "sin.inc" |
nuclear@0 | 138 |
nuclear@0 | 139 tiles: |
nuclear@0 | 140 incbin "logo.tiles" |
nuclear@0 | 141 tiles_end: |
nuclear@0 | 142 tilemap: |
nuclear@0 | 143 incbin "logo.tilemap" |
nuclear@0 | 144 tilemap_end: |