ZX Spectrum konsoles programmēšana ar TASM assembleru Z80 procesoram. Kompilē uzreiz .SNA snapšotā, ko saprot gandrīz jebkurš emulators, arī Speccy, online versija: jsSpeccy. Neizmanto beisiku, tikai ROM apgabalā esošo fontu tabulu. |
; ; ; ZX Spectrum 48 TASM compiled Hello world in .SNA ; ; 64Kb = 16KB ROM + 48KB usable memory ; Screen VRAM and system variables reside after ROM ; SNA file is a snapshot standard used in emulators ; ; Compile with: TASM 80 -b hello.asm hello.sna ; .title Hello Spectrum 48 CPU_ADDR = $60C0 ; where to start (24768) ROM = $4000 ; ROM size in memory (0..16384) SNA_HD = 27 ; header size of .SNA file SNA_SIZE = 49179 ; about 48Kb memory dump size SCREEN = $4000 ; VRAM screen memory STACK_ADDR = $FFFC ; Stack address .org ROM - SNA_HD sna_header: .byte $00 ;0 — i register .word $00 ;1 — l’ register, 2 — h’ register .word $00 ;3 — e’ register, 4 — d’ register .word $00 ;5 — c’ register, 6 — b’ register .word $00 ;7 — f’ register, 8 — a’ register .word $00 ;9 — l register, 10 — h register .word $00 ;11 — e register, 12 — d register .word $00 ;13 — c register, 14 — b register .word $00 ;15 — iy low reg., 16 — iy high reg. .word $00 ;17 — ix low reg., 18 — ix high reg. .byte $ff ;19 — bit 2 contains iff2 .byte $00 ;20 — r register .byte $00 ;21 — flags register .byte $00 ;22 — a register .word STACK_ADDR ;23 — sp low reg., 24 — sp high reg. .byte $01 ;25 — interrupt mode (0, 1 or 2) .byte $05 ;26 — border colour (0..7) ;..49178 — 48 kbytes RAM dump ; address 16384..65535 .ds CPU_ADDR-ROM ; 8438 zeros till address 24768 start: ld a,6 ; yellow color call ClearScreen ; clear screen and ; set ink color to all screen chars ld hl,SCREEN ld de,$3D00 ; charset address in ROM ld bc,STRING ; bc points to the string data in memory loop: ld a,(bc) ; Load a with the byte in location bc or a ; Compare a to 0, set z-flag jr z,smile ; If equal to zero then jump to smile call DrawChar ; Output a to screen inc bc ; Increase bc by one to get next byte inc hl ; Increase hl to next column jr loop ; Jump back to loop smile: ld a,32 ld de,SmileChr ; address of smile bits call DrawChar ; Output a to screen jp * ; stay there... ; subroutines ClearScreen: ;; call with a = ink colour. ld e,a ld hl,SCREEN ld bc,6144 cs0: ld a,0 ld (hl),a inc hl dec bc ld a,b or c jp nz, cs0 ld bc,768 cs1: ld (hl),e inc hl dec bc ld a,b or c jp nz, cs1 ret DrawChar: ;; call with a = ascii character code. ;; hl = screen address. ;; de = charset table push bc push de push hl sub 32 ;; 32 = space = first char = 0, so sub 32 ! push hl ld h,0 ld l,a add hl,hl ;; multiply by 8. add hl,hl add hl,hl add hl,de ex de,hl ;; de = address of char data. pop hl ld c,8 dc0: ld a,(de) ld (hl),a inc h inc de dec c jp nz, dc0 pop hl pop de pop bc ret STRING: .byte "Hello World!" .byte 0 ; end of STRING data SmileChr: .byte % 00111100 .byte % 01000010 .byte % 10100101 .byte % 10000001 .byte % 10100101 .byte % 10011001 .byte % 01000010 .byte % 00111100 sna_file_tail: .ds SNA_SIZE+ROM-SNA_HD-4-* .word CPU_ADDR, $00 ; total 49179 bytes now ; To get SNA 128 version simply do steps after ; to the "hello.sna" file ; (because TASM does it clamsy way): ; 1. add 2 bytes CPU_ADDR (PC, for this sample 0xC0,0x60 ) ; 2. then add byte 0x10 (port 0x7ffd setting) ; 3. then finally add 81921 zero bytes ; upto filesize 131103 bytes ; It works on emulators. The model will be ZX Spectrum 128Kb .endJa esat izlēmuši ko iesākt, tad priekš ZX Spectrum ieteiktu sjasmplus assemblera kompilatoru. Sintakse tā pati, bet ērti kompilēt gatavu kodu, nedomājot par sarežģītiem SNA baitiem. Piemērs ir šeit. Turklāt Spectrum 128Kb datus iekš SNA var iekļaut viegli:
page 6
org $C000
incbin "BANK6.bin"
Protams, Z80 programmēšana ir vieglāka ar SDCC un z88dk. Z80 bija nedaudz dārgāks par 6502, arī vairāk advancēts, tomēr vairāk prieku par mazāku naudu pircēji izvēlējās, pērkot 6502 konsoles Commodore, Atari, NES.
Nav komentāru:
Ierakstīt komentāru