gb_test2

annotate test.asm @ 2:a8b7297e7e2c

corrected comment
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Jan 2019 04:48:34 +0200
parents d63782badb6b
children d7c6e1165028
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@1 49
nuclear@0 50 ldh a, [REG_LY]
nuclear@1 51 add a, d ; add frame number
nuclear@0 52 ld c, a
nuclear@0 53
nuclear@0 54 ld hl, sintab
nuclear@1 55 add hl, bc ; hl now points to the sine value
nuclear@0 56
nuclear@1 57 ld a, [hl]
nuclear@1 58
nuclear@1 59 ; add a half-octave sine
nuclear@1 60 ld e, a ; save first sine to e
nuclear@1 61 sla d
nuclear@1 62 ld a, [REG_LY]
nuclear@1 63 sla a
nuclear@1 64 add a, d
nuclear@1 65 ld c, a
nuclear@1 66 srl d
nuclear@1 67
nuclear@1 68 ld hl, sintab
nuclear@1 69 add hl, bc
nuclear@1 70 ld a, [hl]
nuclear@1 71 sra a
nuclear@1 72 add a, e ; add previously saved sine
nuclear@1 73
nuclear@1 74 add a, yoffs_center
nuclear@0 75 ldh [REG_SCY], a
nuclear@0 76
nuclear@1 77 ; do something for SCX too
nuclear@1 78 ld a, d
nuclear@1 79 sla a
nuclear@1 80 ld d, a
nuclear@1 81
nuclear@1 82 ldh a, [REG_LY]
nuclear@1 83 add a, 32
nuclear@1 84 add a, d ; add frame number
nuclear@1 85 ld c, a
nuclear@1 86
nuclear@1 87 ld hl, sintab
nuclear@1 88 add hl, bc
nuclear@1 89
nuclear@1 90 ld a, [hl]
nuclear@1 91 sra a
nuclear@1 92 add a, xoffs_center
nuclear@1 93 ldh [REG_SCX], a
nuclear@1 94
nuclear@0 95 ; done, wait until we're out of hsync
nuclear@0 96 .wait_endhsync:
nuclear@0 97 ldh a, [REG_STAT]
nuclear@0 98 and a, STAT_MODE_MASK
nuclear@0 99 jr z, .wait_endhsync
nuclear@0 100
nuclear@0 101 jr .mainloop
nuclear@0 102
nuclear@0 103
nuclear@0 104 di
nuclear@0 105 .end: halt
nuclear@0 106 nop
nuclear@0 107 jp .end
nuclear@0 108
nuclear@0 109 init:
nuclear@0 110 call wait_vsync
nuclear@0 111 xor a, a
nuclear@0 112 ldh [REG_LCDC], a
nuclear@0 113
nuclear@2 114 ; setup palette
nuclear@0 115 ld a, $1b
nuclear@0 116 ldh [REG_BGP], a
nuclear@0 117
nuclear@0 118 ; copy tiles
nuclear@0 119 ld hl, $8000
nuclear@0 120 ld de, tiles
nuclear@0 121 ld bc, tiles_end - tiles
nuclear@0 122 .copytiles:
nuclear@0 123 ld a, [de]
nuclear@0 124 ld [hl+], a
nuclear@0 125 inc de
nuclear@0 126 dec bc
nuclear@0 127 ld a, b
nuclear@0 128 or c
nuclear@0 129 jp nz, .copytiles
nuclear@0 130
nuclear@0 131 ; copy tilemap
nuclear@0 132 ld hl, $9800
nuclear@0 133 ld de, tilemap
nuclear@0 134 ld b, 21
nuclear@0 135 .copymap:
nuclear@0 136 ld c, 21
nuclear@0 137 .copymaprow:
nuclear@0 138 ld a, [de]
nuclear@0 139 inc de
nuclear@0 140 ld [hl+], a
nuclear@0 141 dec c
nuclear@0 142 jr nz, .copymaprow
nuclear@0 143
nuclear@0 144 push bc
nuclear@0 145 ld bc, 11
nuclear@0 146 add hl, bc
nuclear@0 147 pop bc
nuclear@0 148
nuclear@0 149 dec b
nuclear@0 150 jr nz, .copymap
nuclear@0 151
nuclear@0 152 ; center viewport
nuclear@0 153 ld a, yoffs_center
nuclear@0 154 ldh [REG_SCY], a
nuclear@0 155 ld a, xoffs_center
nuclear@0 156 ldh [REG_SCX], a
nuclear@0 157
nuclear@0 158 ; configure LCD
nuclear@0 159 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
nuclear@0 160 ldh [REG_LCDC], a
nuclear@0 161 ret
nuclear@0 162
nuclear@0 163 wait_vsync:
nuclear@0 164 ldh a, [REG_LY]
nuclear@0 165 cp a, 144
nuclear@0 166 jr c, wait_vsync
nuclear@0 167 ret
nuclear@0 168
nuclear@0 169 section "data", ROM0, align[8]
nuclear@0 170 sintab:
nuclear@0 171 include "sin.inc"
nuclear@0 172
nuclear@0 173 tiles:
nuclear@0 174 incbin "logo.tiles"
nuclear@0 175 tiles_end:
nuclear@0 176 tilemap:
nuclear@0 177 incbin "logo.tilemap"
nuclear@0 178 tilemap_end: