Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM ###########################
- REM NETOS v1.2
- REM ###########################
- NETOS_BOOTLOADER:
- MOV NETOS_BOOTLOADER_SEG2
- REM ###############################
- REM Print null-str at [A] on a
- REM new line
- REM ###############################
- PrintLn:
- SET PUSH, B
- REM # Load line to B
- JSR LoadNextLine
- JSR PrintStr
- SET B, POP
- SET PC, POP
- REM ###############################
- REM Print null-str at [A]
- REM ###############################
- PrintStr:
- SET PUSH, C
- PrintStr_loop:
- IFE [A], 0
- SET PC, PrintStr_exit
- SET C, [A]
- BOR C, 0x1900
- SET [B], C
- ADD A, 1
- ADD B, 1
- MOV PrintStr_loop
- PrintStr_exit:
- SET C, POP
- SET PC, POP
- REM ###############################
- REM Print a hex number A to [B]
- REM ###############################
- PrintHex:
- PUSHA
- REM # "0x"
- SET [B], 0x1930
- ADD B, 1
- SET [B], 0x1978
- ADD B, 1
- SET I, 12
- PrintHex_loop:
- SET C, A
- SHR C, I
- AND C, 0x000f
- ADD C, 0x30
- BOR C, 0x1900
- SET [B], C
- ADD B, 1
- SUB I, 4
- IFA I, 0xffff
- SET PC, PrintHex_loop
- POPA
- SET PC, POP
- REM #################################
- REM Print a character C to [B++]
- REM #################################
- PrintChar:
- SET PUSH, A
- REM # Check for end of line
- SET A, [@NextPrint]
- ADD A, 0x1E
- IFG B, A
- MOV PrintChar_skip
- SET [B], C
- BOR [B], 0x1900
- ADD B, 1
- PrintChar_skip:
- SET [B], 0x199D
- SET A, POP
- SET PC, POP
- REM ##################################
- REM Clears screen at [--B]
- REM ##################################
- PrintBackspace:
- SET PUSH, A
- SET [B], 0x1920
- REM # Check for start of line
- SET A, [@NextPrint]
- ADD A, 3
- IFL B, A
- MOV PrintBackspace_skip
- SUB B, 1
- SET [B], 0x1920
- PrintBackspace_skip:
- SET [B], 0x199D
- SET A, POP
- SET PC, POP
- REM #################################
- REM Loads the address of the next
- REM line into B
- REM #################################
- LoadNextLine:
- ADD [@NextPrint], 0x20
- IFG [@NextPrint], [@ScreenEnd]
- JSR ScrollUp
- SET B, [@NextPrint]
- SET PC, POP
- REM #################################
- REM Scroll the screen up a line
- REM #################################
- ScrollUp:
- SET PUSH, C
- SET PUSH, I
- SET I, [@ScreenStart]
- SET C, [@ScreenEnd]
- SUB C, 0x1F
- SET [@NextPrint], C
- ScrollUp_loop:
- SET [I], [I + 0x20]
- SET [I + 0x20], 0x1920
- ADD I, 1
- IFL I, C
- SET PC, ScrollUp_loop
- SET I, POP
- SET C, POP
- SET PC, POP
- REM #################################
- REM If string [A] == string [B] then
- REM JSR to C and then
- REM return to I if I != 0
- REM else do nothing
- REM #################################
- StrEquals:
- PUSHA
- StrEquals_loop:
- IFN [A], [B]
- MOV StrEquals_nomatch
- IFE [A], 0
- IFE [B], 0
- MOV StrEquals_match
- ADD A, 1
- ADD B, 1
- MOV StrEquals_loop
- StrEquals_match:
- JSR C
- IFE I, 0
- MOV StrEquals_nomatch
- POPA
- REM # Clear PC from stack
- SET [@ClearPC], POP
- SET PC, I
- REM # No match found
- StrEquals_nomatch:
- POPA
- SET PC, POP
- REM ##################################
- REM Wait for a hex number with then
- REM format #### to be entered
- REM ##################################
- WaitForNumber:
- SET PUSH, B
- SET PUSH, C
- BRK
- REM # Load line to B
- JSR LoadNextLine
- REM # >
- SET [B], 0x193E
- ADD B, 2
- SET [B], 0x199D
- SET C, &InputNumber
- JSR SetKeyCallback
- SET C, POP
- SET B, POP
- SET PC, POP
- REM # Input line Callback
- &InputNumber:
- SET PUSH, A
- SET PUSH, C
- SET A, 1
- HWI 1
- IFE C, 0x10
- JSR PrintBackspace
- IFE C, 0x11
- MOV &InputNumber_done
- REM # Shorter char range check
- SET A, [@NextPrint]
- ADD A, 0x5
- IFG B, A
- MOV &InputNumber_exit
- REM # 0-9
- IFG C, 0x2F
- IFL C, 0x3A
- JSR PrintChar
- REM # a-f
- IFG C, 0x60
- IFL C, 0x67
- JSR PrintChar
- REM # Not done yet
- MOV &InputNumber_exit
- &InputNumber_done:
- SET [B], 0x1920
- JSR ClearKeyCallback
- &InputNumber_exit:
- SET C, POP
- SET A, POP
- SET PC, POP
- REM #################################
- REM Parses a number stored in @Input
- REM and stores the result in C
- REM If error I == 0xffff
- REM #################################
- ParseNumber:
- SET PUSH, A
- SET PUSH, B
- SET I, 12
- SET A, @Input
- ParseNumber_loop:
- SET B, [A]
- REM # 0-9
- IFL B, 0x3A
- SUB B, 0x30
- REM # a-f
- IFG B, 0x60
- IFL B, 0x67
- SUB B, 0x57
- IFG B, 0xF
- MOV ParseNumber_bad
- REM # Add to number
- SHL B, I
- ADD C, B
- ADD A, 1
- SUB I, 4
- REM # IF > -1
- IFA I, 0xffff
- MOV ParseNumber_loop
- REM # Is a 4 char number
- IFE [A], 0x20
- MOV ParseNumber_done
- IFE [A], 0x00
- MOV ParseNumber_done
- REM # Bad input
- ParseNumber_bad:
- SET I, 0xffff
- SET A, $InvalidInput
- JSR PrintLn
- ParseNumber_done:
- SET B, POP
- SET A, POP
- SET PC, POP
- REM ##################################
- REM Wait for a command to be entered
- REM ##################################
- WaitForString:
- SET PUSH, B
- SET PUSH, C
- REM # Load line to B
- JSR LoadNextLine
- REM # >
- SET [B], 0x193E
- ADD B, 2
- SET [B], 0x199D
- SET C, &InputLine
- JSR SetKeyCallback
- SET C, POP
- SET B, POP
- SET PC, POP
- REM # Input line Callback
- &InputLine:
- SET PUSH, A
- SET PUSH, C
- SET A, 1
- HWI 1
- IFE C, 0x10
- JSR PrintBackspace
- IFE C, 0x11
- MOV &InputLine_done
- IFG C, 0x1F
- IFL C, 0x80
- JSR PrintChar
- REM # Not done
- MOV &InputLine_exit
- &InputLine_done:
- SET [B], 0x1920
- JSR ClearKeyCallback
- JSR ParseLineInput
- &InputLine_exit:
- SET C, POP
- SET A, POP
- SET PC, POP
- REM #################################
- REM Parses the input out of this line
- REM #################################
- ParseLineInput:
- SET PUSH, A
- SET PUSH, B
- SET A, @Input
- SET B, [@NextPrint]
- ADD B, 2
- ParseLineInput_loop:
- IFE [B], 0x1920
- MOV ParseLineInput_end
- SET [A], [B]
- AND [A], 0x00ff
- ADD A, 1
- ADD B, 1
- MOV ParseLineInput_loop
- ParseLineInput_end:
- REM # End with null
- SET [A], 0
- SET B, POP
- SET A, POP
- SET PC, POP
- REM ##################################
- REM Set an event for a keyboard event
- REM Will MOV to C when event triggers
- REM Hangs until @KeyHandler == 0
- REM ##################################
- SetKeyCallback:
- SET PUSH, A
- SET PUSH, B
- SET A, 3
- SET B, C
- SET [@KeyHandler], B
- HWI 1
- SET B, POP
- SET A, POP
- REM # Wait for the state to update
- SetKeyCallback_wait:
- IFN [@KeyHandler], 0
- SET PC, SetKeyCallback_wait
- SET PC, POP
- REM ##################################
- REM Clears a KeyCallback
- REM ##################################
- ClearKeyCallback:
- SET PUSH, A
- SET PUSH, B
- SET [@KeyHandler], 0x0000
- SET A, 0
- HWI 1
- SET A, 3
- SET B, 0
- HWI 1
- SET A, POP
- SET B, POP
- SET PC, POP
- REM ##################################
- REM Starts a timeout which will MOV
- REM to B after A seconds
- REM ##################################
- SetTimeout:
- SET PUSH, A
- SET PUSH, B
- SET [@TimeoutTicks], A
- SET [@TimeoutHandler], B
- REM # Int with message B
- SET A, 2
- HWI 2
- REM # Start timer
- SET A, 0
- SET B, 60
- HWI 2
- SET B, POP
- SET A, POP
- SET PC, POP
- REM ##################################
- REM Checks for timeout completion, if
- REM done moves to the timeout address
- REM ##################################
- DoTimeout:
- SET PUSH, C
- REM # Get ticks
- SET A, 1
- HWI 2
- REM # If less than timeout ticks skip
- IFL C, [@TimeoutTicks]
- MOV DoTimeout_notyet
- SET C, POP
- REM # Reset from JSR
- SET [@ClearPC], POP
- REM # Reset from interrupt
- SET A, POP
- SET [@ClearPC], POP
- IAQ 0
- REM # Move to timeout handler
- SET PC, [@TimeoutHandler]
- DoTimeout_notyet:
- SET C, POP
- SET PC, POP
- REM ##################################
- REM Clears the current timeout
- REM ##################################
- ClearTimeout:
- SET PUSH, A
- SET PUSH, B
- SET [@TimeoutHandler], 0
- REM # Stop timer
- SET A, 0
- SET B, 0
- HWI 2
- REM # Clear message
- SET A, 2
- SET B, 0
- HWI 2
- SET B, POP
- SET A, POP
- SET PC, POP
- REM ##################################
- REM The hardware interrupt handler
- REM ##################################
- HardwareIterrupt:
- IFE A, 0
- RFI 0x0
- IFE A, [@KeyHandler]
- JSR [@KeyHandler]
- IFE A, [@TimeoutHandler]
- JSR DoTimeout
- RFI 0x0
- REM #############
- REM Attributes
- REM #############
- @ScreenStart:
- DAT 0x8000
- @NextPrint:
- DAT 0x7FE0
- @ScreenEnd:
- DAT 0x817F
- @KeyHandler:
- DAT 0x0000
- @TimeoutHandler:
- DAT 0x0000
- @TimeoutTicks:
- DAT 0x0000
- @IP:
- DAT 0
- @ClearPC:
- DAT 0
- @Input:
- DAT 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- FILL NETOS_BOOTLOADER, 511
- DAT 0x55AA
- REM #################################
- REM The second segment of NETOS
- REM The main code segment
- REM #################################
- NETOS_BOOTLOADER_SEG2:
- REM # Turn on monitor
- SET A, 0
- SET B, [@ScreenStart]
- HWI 0
- IAS HardwareIterrupt
- SET A, $NetOS
- JSR PrintLn
- SET A, $Connecting
- JSR PrintLn
- REM # Wait until connected
- SET A, 0xa
- SET B, 0xffff
- waitForConnection:
- HWI 4
- IFE B, 0xffff
- MOV waitForConnection
- REM # Store IP
- SET [@IP], B
- REM # Print "Connected IP: #"
- SET B, [@NextPrint]
- SET A, $Connected
- JSR PrintStr
- SET A, [@IP]
- JSR PrintHex
- SET A, $EnterHelp
- JSR PrintLn
- REM # Command
- NETOS_BOOTLOADER_Input_Loop:
- JSR WaitForString
- JSR RunInput
- MOV NETOS_BOOTLOADER_Input_Loop
- NETOS_BOOTLOADER_Input_Break:
- JSR PressAnyKey
- REM # Quit
- NETOS_BOOTLOADER_Quit:
- SET A, $Done
- JSR PrintLn
- HNG
- REM #################################
- REM Run the command stored in @Input
- REM #################################
- RunInput:
- PUSHA
- REM # Check for commands
- SET A, @Input
- SET I, RunInput_exit
- SET B, >connect
- SET C, Connect
- JSR StrEquals
- SET B, >help
- SET C, Print_Help
- JSR StrEquals
- SET B, >exit
- SET C, NETOS_BOOTLOADER_Quit
- JSR StrEquals
- REM # End check for commands
- REM # Didn't skip to RunInput_exit
- REM # so no match
- SET A, $UnknownCmd
- JSR PrintLn
- JSR LoadNextLine
- ADD B, 1
- SET A, @Input
- JSR PrintStr
- RunInput_exit:
- POPA
- SET PC, POP
- REM #################################
- REM Wait for a key to be pressed
- REM #################################
- PressAnyKey:
- SET PUSH, A
- SET PUSH, C
- SET A, $AnyKey
- JSR PrintLn
- SET C, &PressAnyKey
- JSR SetKeyCallback
- SET C, POP
- SET A, POP
- SET PC, POP
- REM # AnyKeyPressed Callback
- &PressAnyKey:
- SET PUSH, A
- SET A, 1
- HWI 1
- IFN C, 0x0
- JSR ClearKeyCallback
- SET A, POP
- SET PC, POP
- REM #################################
- REM Send a ping packet to the IP in
- REM C at port 64
- REM #################################
- PingIP:
- SET PUSH, A
- SET PUSH, B
- REM # Open ping port
- SET A, 0
- SET B, 64
- HWI 4
- REM # Set target
- SET A, 3
- REM # Move IP to B
- SET B, C
- SET C, 64
- HWI 1
- REM # Append 1
- SET A, 4
- SET B, 1
- HWI 1
- REM # Send packet
- SET A, 5
- HWI 1
- SET A, 3
- SET B, &PacketTimeout
- JSR SetTimeout
- PingIP_hang:
- SET PC, PingIP_hang
- &PacketTimeout:
- SET A, $NoResponse
- JSR PrintLn
- PingIP_exit:
- JSR ClearTimeout
- REM # Close ping port
- SET A, 1
- SET B, 64
- HWI 4
- REM # Clear packet buffer
- SET A, 0xC
- HWI 4
- SET B, POP
- SET A, POP
- SET PC, POP
- REM #################################
- REM Connect to a server on port 64
- REM #################################
- Connect:
- SET PUSH, A
- SET A, $EnterIP
- JSR PrintLn
- JSR WaitForNumber
- JSR ParseLineInput
- JSR ParseNumber
- IFE I, 0xffff
- MOV Connect_exit
- JSR PingIP
- Connect_exit:
- SET A, POP
- SET PC, POP
- REM #################################
- REM Print the help message
- REM #################################
- Print_Help:
- SET PUSH, A
- SET A, $Help_Connect
- JSR PrintLn
- SET A, $Help_Help
- JSR PrintLn
- SET A, $Help_Exit
- JSR PrintLn
- SET A, POP
- SET PC, POP
- REM ##############
- REM Strings
- REM < 32 chars
- REM #############
- $NetOS:
- DAT 'N','E','T','O','S',' ','v','1','.','2', 0x0
- $Connecting:
- DAT 'C','o','n','n','e','c','t','i','n','g','.','.','.', 0x0
- $Connected:
- DAT 'C','o','n','n','e','c','t','e','d',' ','I','P',':',' ', 0x0
- $EnterHelp:
- DAT 'E','n','t','e','r',' ',''','h','e','l','p',''', 0x0
- $AnyKey:
- DAT 'P','r','e','s','s',' ','A','n','y',' ','K','e','y',' ','T','o',' ','C','o','n','t','i','n','u','e','.','.','.', 0x0
- $UnknownCmd:
- DAT 'U','n','k','n','o','w','n',' ','c','o','m','m','a','n','d',':', 0x0
- $Done:
- DAT 'D','o','n','e', 0x0
- $EnterIP:
- DAT 'E','n','t','e','r',' ','h','e','x',' ','I','P',' ','w','i','t','h',' ','f','o','r','m','a','t',' ','#','#','#','#',':', 0x0
- $InvalidInput:
- DAT 'I','n','v','a','l','i','d',' ','i','n','p','u','t', 0x0
- $NoResponse:
- DAT 'N','o',' ','r','e','s','p','o','n','s','e', 0x0
- REM #############
- REM Commands
- REM #############
- >connect:
- DAT 'c','o','n','n','e','c','t', 0x0
- $Help_Connect:
- DAT 'c','o','n','n','e','c','t',' ','-',' ','C','o','n','n','e','c','t',' ','t','o',' ','a',' ','s','e','r','v','e','r', 0x0
- >help:
- DAT 'h','e','l','p', 0x0
- $Help_Help:
- DAT 'h','e','l','p',' ',' ',' ',' ','-',' ','S','h','o','w',' ','t','h','i','s', 0x0
- >exit:
- DAT 'e','x','i','t', 0x0
- $Help_Exit:
- DAT 'e','x','i','t',' ',' ',' ',' ','-',' ','Q','u','i','t',' ','N','E','T','O','S', 0x0
- FILL NETOS_BOOTLOADER_SEG2, 512
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement