gb_test2
annotate test.asm @ 1:d63782badb6b
nicer distortion
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 10 Jan 2019 04:47:42 +0200 |
parents | cacfa0888410 |
children | a8b7297e7e2c |
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@0 | 114 ; setup identity palette |
nuclear@0 | 115 ld a, $1b |
nuclear@0 | 116 ldh [REG_BGP], a |
nuclear@0 | 117 |
nuclear@0 | 118 |
nuclear@0 | 119 ; copy tiles |
nuclear@0 | 120 ld hl, $8000 |
nuclear@0 | 121 ld de, tiles |
nuclear@0 | 122 ld bc, tiles_end - tiles |
nuclear@0 | 123 .copytiles: |
nuclear@0 | 124 ld a, [de] |
nuclear@0 | 125 ld [hl+], a |
nuclear@0 | 126 inc de |
nuclear@0 | 127 dec bc |
nuclear@0 | 128 ld a, b |
nuclear@0 | 129 or c |
nuclear@0 | 130 jp nz, .copytiles |
nuclear@0 | 131 |
nuclear@0 | 132 ; copy tilemap |
nuclear@0 | 133 ld hl, $9800 |
nuclear@0 | 134 ld de, tilemap |
nuclear@0 | 135 ld b, 21 |
nuclear@0 | 136 .copymap: |
nuclear@0 | 137 ld c, 21 |
nuclear@0 | 138 .copymaprow: |
nuclear@0 | 139 ld a, [de] |
nuclear@0 | 140 inc de |
nuclear@0 | 141 ld [hl+], a |
nuclear@0 | 142 dec c |
nuclear@0 | 143 jr nz, .copymaprow |
nuclear@0 | 144 |
nuclear@0 | 145 push bc |
nuclear@0 | 146 ld bc, 11 |
nuclear@0 | 147 add hl, bc |
nuclear@0 | 148 pop bc |
nuclear@0 | 149 |
nuclear@0 | 150 dec b |
nuclear@0 | 151 jr nz, .copymap |
nuclear@0 | 152 |
nuclear@0 | 153 ; center viewport |
nuclear@0 | 154 ld a, yoffs_center |
nuclear@0 | 155 ldh [REG_SCY], a |
nuclear@0 | 156 ld a, xoffs_center |
nuclear@0 | 157 ldh [REG_SCX], a |
nuclear@0 | 158 |
nuclear@0 | 159 ; configure LCD |
nuclear@0 | 160 ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON |
nuclear@0 | 161 ldh [REG_LCDC], a |
nuclear@0 | 162 ret |
nuclear@0 | 163 |
nuclear@0 | 164 wait_vsync: |
nuclear@0 | 165 ldh a, [REG_LY] |
nuclear@0 | 166 cp a, 144 |
nuclear@0 | 167 jr c, wait_vsync |
nuclear@0 | 168 ret |
nuclear@0 | 169 |
nuclear@0 | 170 section "data", ROM0, align[8] |
nuclear@0 | 171 sintab: |
nuclear@0 | 172 include "sin.inc" |
nuclear@0 | 173 |
nuclear@0 | 174 tiles: |
nuclear@0 | 175 incbin "logo.tiles" |
nuclear@0 | 176 tiles_end: |
nuclear@0 | 177 tilemap: |
nuclear@0 | 178 incbin "logo.tilemap" |
nuclear@0 | 179 tilemap_end: |