Last active
November 28, 2019 17:29
-
-
Save mistificator/ae14f6491d440e557efb817ea644d9e4 to your computer and use it in GitHub Desktop.
Zx Spectrum native ASM Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .org $5CD2 ; // fixed origin for https://clrhome.org/asm/ TAP generator | |
| #define ROM_PR_STRING $203C | |
| #define ROM_OUT_NUM1 $1A1B | |
| #define ROM_CHAN_OPEN $1601 | |
| #define ROM_CLS $0D6B | |
| #define SYSVAR_7FFD_STATE $5B5C ;system variable that holds the last value output to 7FFDh, from https://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter8pt26.html | |
| #define SYSVAR_1FFD_STATE $5B67 ;system variable that holds the last value output to 1FFDh, from http://www.hal.varese.it/filesmuseo/sinclair/spectrumfaq/tech_128.html | |
| #define SYSVAR_LAST_K $5C08 | |
| ImageStart: | |
| jp Start | |
| Select_Screen: ;from https://zxpress.ru/book_articles.php?id=1150 | |
| push hl | |
| ld a,2 | |
| call ROM_CHAN_OPEN ;from https://skoolkid.github.io/rom/asm/1601.html | |
| pop hl | |
| ret | |
| Print: | |
| call Select_Screen | |
| Print_Loop: ;from https://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter8pt26.html | |
| ld a,(hl) ;this just loops printing characters | |
| cp '$' ;until if finds 0x24 ($) | |
| ret z | |
| push hl | |
| rst $10 ;with 48K ROM in, this will print char in A | |
| pop hl | |
| inc hl | |
| jp Print_Loop | |
| Print_NewLine: | |
| ld a,13 | |
| push hl | |
| rst $10 | |
| pop hl | |
| ret | |
| Set_Border_Color: | |
| push de | |
| push bc | |
| ld d,b | |
| ld bc, $FFFE | |
| out (c),d | |
| pop bc | |
| pop de | |
| ret | |
| Start: | |
| xor a | |
| ld (SYSVAR_LAST_K),a ; reset last key | |
| call ROM_CLS | |
| Print_Message: | |
| call Select_Screen | |
| ld de,Message1_Start | |
| ld bc,Message1_End-Message1_Start | |
| call ROM_PR_STRING ; print by ROM, as described in https://zxpress.ru/book_articles.php?id=1150 | |
| call Print_NewLine | |
| ld hl,Message2 | |
| call Print | |
| call Print_NewLine | |
| ld hl,Message_MemoryBank | |
| call Print | |
| ld bc,(SYSVAR_7FFD_STATE) ; current memory bank | |
| call ROM_OUT_NUM1 ; print number by ROM | |
| ld a,'/' | |
| rst $10 | |
| ld bc,(SYSVAR_1FFD_STATE) ; current memory bank | |
| call ROM_OUT_NUM1 ; print number by ROM | |
| call Print_NewLine | |
| ld hl,Message_AnyKey | |
| call Print | |
| Reset_Main_Loop: | |
| ld b, 8 | |
| Main_Loop: | |
| ld a,(SYSVAR_LAST_K) ; read keyboard | |
| cp 0 | |
| jp nz,End ; key pressed, go to exit | |
| call Set_Border_Color ; change border color to b value | |
| djnz Main_Loop | |
| jp Reset_Main_Loop | |
| Message1_Start: | |
| .db "Hello, world!" | |
| Message1_End: | |
| Message2: | |
| .db "It's Z80 assembler test!$" | |
| Message_MemoryBank: | |
| .db "Control ports 7FFD/1FFD: $" | |
| Message_AnyKey: | |
| .db 13,13,"Press any key to boot to BASIC48",13,'$' | |
| End: | |
| ; switching ROMs as described in https://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter8pt24.html | |
| ld a, 16 ; switch ROM horizontal (D4) | |
| ld (SYSVAR_7FFD_STATE), a | |
| ld bc, $7FFD | |
| out (c), a | |
| ld a, 4 ; switch ROM vertical (D2) | |
| ld (SYSVAR_1FFD_STATE), a | |
| ld bc, $1FFD | |
| out (c), a | |
| rst $00 ; reboot | |
| ImageEnd: | |
| ; .ds $4000+ImageStart-ImageEnd, 0 ; // enable this for 16kb ROM generation, and disable .org at beginning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

