|
| 1 | + org 32768 |
| 2 | +.core.__START_PROGRAM: |
| 3 | + di |
| 4 | + push ix |
| 5 | + push iy |
| 6 | + exx |
| 7 | + push hl |
| 8 | + exx |
| 9 | + ld hl, 0 |
| 10 | + add hl, sp |
| 11 | + ld (.core.__CALL_BACK__), hl |
| 12 | + ei |
| 13 | + jp .core.__MAIN_PROGRAM__ |
| 14 | +.core.__CALL_BACK__: |
| 15 | + DEFW 0 |
| 16 | +.core.ZXBASIC_USER_DATA: |
| 17 | + ; Defines USER DATA Length in bytes |
| 18 | +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA |
| 19 | + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN |
| 20 | + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA |
| 21 | +_score: |
| 22 | + DEFB 70h |
| 23 | + DEFB 11h |
| 24 | + DEFB 01h |
| 25 | + DEFB 00h |
| 26 | +_r: |
| 27 | + DEFW .LABEL.__LABEL0 |
| 28 | +_r.__DATA__.__PTR__: |
| 29 | + DEFW _r.__DATA__ |
| 30 | +_r.__DATA__: |
| 31 | + DEFB 40h |
| 32 | + DEFB 9Ch |
| 33 | + DEFB 00h |
| 34 | + DEFB 00h |
| 35 | + DEFB 0B8h |
| 36 | + DEFB 88h |
| 37 | + DEFB 00h |
| 38 | + DEFB 00h |
| 39 | + DEFB 30h |
| 40 | + DEFB 75h |
| 41 | + DEFB 00h |
| 42 | + DEFB 00h |
| 43 | + DEFB 0A8h |
| 44 | + DEFB 61h |
| 45 | + DEFB 00h |
| 46 | + DEFB 00h |
| 47 | + DEFB 20h |
| 48 | + DEFB 4Eh |
| 49 | + DEFB 00h |
| 50 | + DEFB 00h |
| 51 | + DEFB 98h |
| 52 | + DEFB 3Ah |
| 53 | + DEFB 00h |
| 54 | + DEFB 00h |
| 55 | + DEFB 10h |
| 56 | + DEFB 27h |
| 57 | + DEFB 00h |
| 58 | + DEFB 00h |
| 59 | +.LABEL.__LABEL0: |
| 60 | + DEFW 0000h |
| 61 | + DEFB 04h |
| 62 | +.core.ZXBASIC_USER_DATA_END: |
| 63 | +.core.__MAIN_PROGRAM__: |
| 64 | + ld de, 1 |
| 65 | + ld hl, 14464 |
| 66 | + push de |
| 67 | + push hl |
| 68 | + call _main |
| 69 | + ld hl, (_r.__DATA__ + 0) |
| 70 | + ld de, (_r.__DATA__ + 0 + 2) |
| 71 | + ld a, l |
| 72 | + ld (0), a |
| 73 | + ld hl, 0 |
| 74 | + ld b, h |
| 75 | + ld c, l |
| 76 | +.core.__END_PROGRAM: |
| 77 | + di |
| 78 | + ld hl, (.core.__CALL_BACK__) |
| 79 | + ld sp, hl |
| 80 | + exx |
| 81 | + pop hl |
| 82 | + exx |
| 83 | + pop iy |
| 84 | + pop ix |
| 85 | + ei |
| 86 | + ret |
| 87 | +_main: |
| 88 | + push ix |
| 89 | + ld ix, 0 |
| 90 | + add ix, sp |
| 91 | + ld hl, 0 |
| 92 | + push hl |
| 93 | + ld l, (ix-2) |
| 94 | + ld h, (ix-1) |
| 95 | + push hl |
| 96 | + ld hl, _r |
| 97 | + call .core.__ARRAY |
| 98 | + ld de, 1 |
| 99 | + ld bc, 4464 |
| 100 | + call .core.__STORE32 |
| 101 | + ld l, (ix-2) |
| 102 | + ld h, (ix-1) |
| 103 | + push hl |
| 104 | + ld hl, _r |
| 105 | + call .core.__ARRAY |
| 106 | + ld bc, (_score) |
| 107 | + ld de, (_score + 2) |
| 108 | + call .core.__STORE32 |
| 109 | + ld l, (ix+4) |
| 110 | + ld h, (ix+5) |
| 111 | + ld e, (ix+6) |
| 112 | + ld d, (ix+7) |
| 113 | + push de |
| 114 | + push hl |
| 115 | + ld l, (ix-2) |
| 116 | + ld h, (ix-1) |
| 117 | + inc hl |
| 118 | + push hl |
| 119 | + ld hl, _r |
| 120 | + call .core.__ARRAY |
| 121 | + pop bc |
| 122 | + pop de |
| 123 | + call .core.__STORE32 |
| 124 | +_main__leave: |
| 125 | + ld sp, ix |
| 126 | + pop ix |
| 127 | + exx |
| 128 | + pop hl |
| 129 | + pop bc |
| 130 | + ex (sp), hl |
| 131 | + exx |
| 132 | + ret |
| 133 | + ;; --- end of user code --- |
| 134 | +#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 135 | +; vim: ts=4:et:sw=4: |
| 136 | + ; Copyleft (K) by Jose M. Rodriguez de la Rosa |
| 137 | + ; (a.k.a. Boriel) |
| 138 | +; http://www.boriel.com |
| 139 | + ; ------------------------------------------------------------------- |
| 140 | + ; Simple array Index routine |
| 141 | + ; Number of total indexes dimensions - 1 at beginning of memory |
| 142 | + ; HL = Start of array memory (First two bytes contains N-1 dimensions) |
| 143 | + ; Dimension values on the stack, (top of the stack, highest dimension) |
| 144 | + ; E.g. A(2, 4) -> PUSH <4>; PUSH <2> |
| 145 | + ; For any array of N dimension A(aN-1, ..., a1, a0) |
| 146 | + ; and dimensions D[bN-1, ..., b1, b0], the offset is calculated as |
| 147 | + ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] |
| 148 | +; What I will do here is to calculate the following sequence: |
| 149 | + ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... |
| 150 | +#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" |
| 151 | + push namespace core |
| 152 | +__MUL16: ; Mutiplies HL with the last value stored into de stack |
| 153 | + ; Works for both signed and unsigned |
| 154 | + PROC |
| 155 | + LOCAL __MUL16LOOP |
| 156 | + LOCAL __MUL16NOADD |
| 157 | + ex de, hl |
| 158 | + pop hl ; Return address |
| 159 | + ex (sp), hl ; CALLEE caller convention |
| 160 | +__MUL16_FAST: |
| 161 | + ld b, 16 |
| 162 | + ld a, h |
| 163 | + ld c, l |
| 164 | + ld hl, 0 |
| 165 | +__MUL16LOOP: |
| 166 | + add hl, hl ; hl << 1 |
| 167 | + sla c |
| 168 | + rla ; a,c << 1 |
| 169 | + jp nc, __MUL16NOADD |
| 170 | + add hl, de |
| 171 | +__MUL16NOADD: |
| 172 | + djnz __MUL16LOOP |
| 173 | + ret ; Result in hl (16 lower bits) |
| 174 | + ENDP |
| 175 | + pop namespace |
| 176 | +#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 177 | +#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 178 | + push namespace core |
| 179 | +__ARRAY_PTR: ;; computes an array offset from a pointer |
| 180 | + ld c, (hl) |
| 181 | + inc hl |
| 182 | + ld h, (hl) |
| 183 | + ld l, c |
| 184 | +__ARRAY: |
| 185 | + PROC |
| 186 | + LOCAL LOOP |
| 187 | + LOCAL ARRAY_END |
| 188 | + LOCAL RET_ADDRESS ; Stores return address |
| 189 | + LOCAL TMP_ARR_PTR ; Stores pointer temporarily |
| 190 | + ld e, (hl) |
| 191 | + inc hl |
| 192 | + ld d, (hl) |
| 193 | + inc hl |
| 194 | + ld (TMP_ARR_PTR), hl |
| 195 | + ex de, hl |
| 196 | + ex (sp), hl ; Return address in HL, array address in the stack |
| 197 | + ld (RET_ADDRESS + 1), hl ; Stores it for later |
| 198 | + exx |
| 199 | + pop hl ; Will use H'L' as the pointer |
| 200 | + ld c, (hl) ; Loads Number of dimensions from (hl) |
| 201 | + inc hl |
| 202 | + ld b, (hl) |
| 203 | + inc hl ; Ready |
| 204 | + exx |
| 205 | + ld hl, 0 ; HL = Offset "accumulator" |
| 206 | +LOOP: |
| 207 | +#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 208 | + pop bc ; Get next index (Ai) from the stack |
| 209 | +#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 210 | + add hl, bc ; Adds current index |
| 211 | + exx ; Checks if B'C' = 0 |
| 212 | + ld a, b ; Which means we must exit (last element is not multiplied by anything) |
| 213 | + or c |
| 214 | + jr z, ARRAY_END ; if B'Ci == 0 we are done |
| 215 | + ld e, (hl) ; Loads next dimension into D'E' |
| 216 | + inc hl |
| 217 | + ld d, (hl) |
| 218 | + inc hl |
| 219 | + push de |
| 220 | + dec bc ; Decrements loop counter |
| 221 | + exx |
| 222 | + pop de ; DE = Max bound Number (i-th dimension) |
| 223 | + call __FNMUL |
| 224 | + jp LOOP |
| 225 | +ARRAY_END: |
| 226 | + ld a, (hl) |
| 227 | + exx |
| 228 | +#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 229 | + LOCAL ARRAY_SIZE_LOOP |
| 230 | + ex de, hl |
| 231 | + ld hl, 0 |
| 232 | + ld b, a |
| 233 | +ARRAY_SIZE_LOOP: |
| 234 | + add hl, de |
| 235 | + djnz ARRAY_SIZE_LOOP |
| 236 | +#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" |
| 237 | + ex de, hl |
| 238 | + ld hl, (TMP_ARR_PTR) |
| 239 | + ld a, (hl) |
| 240 | + inc hl |
| 241 | + ld h, (hl) |
| 242 | + ld l, a |
| 243 | + add hl, de ; Adds element start |
| 244 | +RET_ADDRESS: |
| 245 | + jp 0 |
| 246 | + ;; Performs a faster multiply for little 16bit numbs |
| 247 | + LOCAL __FNMUL, __FNMUL2 |
| 248 | +__FNMUL: |
| 249 | + xor a |
| 250 | + or h |
| 251 | + jp nz, __MUL16_FAST |
| 252 | + or l |
| 253 | + ret z |
| 254 | + cp 33 |
| 255 | + jp nc, __MUL16_FAST |
| 256 | + ld b, l |
| 257 | + ld l, h ; HL = 0 |
| 258 | +__FNMUL2: |
| 259 | + add hl, de |
| 260 | + djnz __FNMUL2 |
| 261 | + ret |
| 262 | +TMP_ARR_PTR: |
| 263 | + DW 0 ; temporary storage for pointer to tables |
| 264 | + ENDP |
| 265 | + pop namespace |
| 266 | +#line 72 "zx48k/astore32.bas" |
| 267 | +#line 1 "/zxbasic/src/arch/zx48k/library-asm/store32.asm" |
| 268 | + push namespace core |
| 269 | +__PISTORE32: |
| 270 | + push hl |
| 271 | + push ix |
| 272 | + pop hl |
| 273 | + add hl, bc |
| 274 | + pop bc |
| 275 | +__ISTORE32: ; Load address at hl, and stores E,D,B,C integer at that address |
| 276 | + ld a, (hl) |
| 277 | + inc hl |
| 278 | + ld h, (hl) |
| 279 | + ld l, a |
| 280 | +__STORE32: ; Stores the given integer in DEBC at address HL |
| 281 | + ld (hl), c |
| 282 | + inc hl |
| 283 | + ld (hl), b |
| 284 | + inc hl |
| 285 | + ld (hl), e |
| 286 | + inc hl |
| 287 | + ld (hl), d |
| 288 | + ret |
| 289 | + pop namespace |
| 290 | +#line 73 "zx48k/astore32.bas" |
| 291 | + END |
0 commit comments