Last active
January 18, 2024 09:58
-
-
Save lukad/6105265 to your computer and use it in GitHub Desktop.
My hello world program in DCPU-16 ASM.
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
JSR main | |
; Main | |
:main | |
JSR setup ; Setup the hardware | |
SET A, msg ; Store msg in A for print_message | |
JSR print_message ; Print our message | |
SET PC, end ; End the program | |
; Hardware setup | |
:setup | |
HWN I ; Store number of connected devices in I | |
JSR map_hardware ; Setup the hardware | |
SET PC, POP ; Return to main | |
; Setup the hardware | |
; Iterate over all connected devices | |
:map_hardware | |
SUB I, 0x1 ; Subtract 1 from I each time the loop runs | |
HWQ I ; Harware query stores first part of the HW ID in | |
; B and the second part in A | |
IFE B, 0x7349 ; Check for LEM1802 (ID=7349F615) | |
IFE A, 0xF615 | |
JSR setup_screen ; Setup the screen | |
IFE I, 0x0 ; If I is 0, all devices have been checked/setup | |
SET PC, POP ; Return to setup | |
SET PC, map_hardware ; Otherwise loop | |
; Setup the LEM1802 | |
:setup_screen | |
SET [screen], I ; Store screen ID at address of screen | |
SET A, 0 ; MEM_MAP_SCREEN map video memory to address starting at B | |
SET B, 0x8000 ; video memory starting address | |
HWI [screen] ; Send interrupt to device | |
SET PC, POP ; return to map_hardware | |
; Print 0 terminated string starting at A at | |
:print_message | |
SET PUSH, I ; Counter for the cursor position | |
SET I, 0x0 ; Set it to 0 | |
:print_message_loop | |
IFE [A], 0 ; Check if char is 0 | |
SET PC, print_message_end ; End the loop | |
SET J, [A] ; Store current character in J | |
BOR J, 0xA000 ; Set color to light green | |
SET [0x8000+I], J ; Print the character | |
ADD I, 0x1 ; Increment counter | |
ADD A, 0x1 | |
SET PC, print_message_loop ; Loop | |
:print_message_end | |
SET I, POP ; POP I | |
SET PC, POP ; Return | |
:end SUB PC, end | |
; The Message we want to print | |
:msg dat "Hello, World!", 0x0 | |
; The screen ID will be stored here | |
:screen dat 0x0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment