#53 - BASIC Z80 Machine Code Hex Loader (Sinclair ZX Spectrum / Next)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • A BASIC loader program to convert Hexadecimal Machine Code bytes into Decimal Values, store them in memory and execute the program.
    HEX LOADER PROGRAM:
    Note: Angled brackets are not allowed in TH-cam descriptions so replace the [LESS THAN] and [GREATER THAN] placeholders in lines 2030 and 2040 with the appropriate symbols.
    ===============
    10 REM [A simple BASIC program to save and execute a machine code program in memory]
    20 RESTORE 5000: REM [Refresh DATA]
    30 CLS:REM [Clear the display]
    40 PRINT "Press a key to load M.C. program"
    50 PAUSE 0: REM [Wait for user to press a key]
    60 LET memory=40000: REM [Initialize "memory" varible to store address locations for MC]
    70 dim b(2):LET b(1)=16: LET b(2)=1: REM [Initialize hex digit multipliers]
    80 spectrum chr$64 :REM [64 column mode]
    100 READ i$: REM [Read z80 assembly instruction description]
    110 PRINT 'i$,: REM [Print z80 assembly instruction]
    120 READ bytenum: REM [Read number of MC bytes for instruction]
    130 PRINT "Bytes: ";bytenum
    140 FOR f=1 to bytenum: REM [Set loop counter for number of bytes]
    150 READ b$: REM [Read a MC byte into the variable "b$"]
    152 GOSUB 2000: REM [Convert hex value to decimal and put in "byte"]
    160 POKE memory,byte : REM [Save MC byte to memory address]
    170 PRINT memory,b$;" ("; PEEK (memory);")": REM [Print memory address and MC byte]
    180 IF byte=201 THEN GOTO 1000: REM [Check for RETURN instruction (201)]
    190 LET memory=memory+1: REM [Incrememt memory address]
    200 NEXT f: REM [Go read next MC byte]
    210 PRINT '"Press a key for next instruction"
    220 PAUSE 0: REM [Wait for user input]
    230 GOTO 100: REM [Go read next z80 instruction]
    1000 PRINT '"Press any key to execute M.C."
    1010 PAUSE 0: REM [Wait for user input]
    1020 RANDOMIZE usr 40000: REM [Execute MC program (stored at address 40000)]
    1999 STOP : REM [End program once MC has finished executing]
    2000 REM [Convert b$ to decimal number and assign to variable "byte"]
    2010 LET byte=0: REM [Reset mc "byte" value]
    2020 FOR g=1 TO 2
    2030 IF CODE b$(g) [LESS THAN] 48 or CODE b$(g) [GREATER THAN] 70 then print ink 2; "Invalid hex value:";b$:stop
    2040 IF CODE b$(g) [GREATER THAN] 64 THEN LET byte=byte + (CODE b$(g)-55)*b(g): GOTO 2060
    2050 LET byte=byte+(CODE b$(g)-48)*b(g)
    2060 NEXT g
    2070 RETURN
    5000 REM [MACHINE CODE BYTES BELOW]
    5100 DATA "LD A,4",2,"3E","04":REM [Load border color (red) into register A]
    5200 DATA "OUT (FE),A",2,"D3","FE":REM [Set border to color stored in register A]
    9000 DATA "RETURN",1,"C9":REM [Return to BASIC]
    ====================
    Download Spriteworx games at:
    spriteworx.itc...
    Join my free Spriteworx Facebook Page (public):
    / spriteworx
    Help support more projects by becoming a Patreon subscriber:
    / spriteworx
    Private facebook group with downloadable content for Patreon subscribers:
    / spriteworx

ความคิดเห็น • 3

  • @Matefromthepast
    @Matefromthepast 2 ปีที่แล้ว +1

    Great to see you back!

  • @robm8809
    @robm8809 2 ปีที่แล้ว +1

    Thanks again! I'm just a beginner and am looking forward to rewatching these and learning a lot more from them, cheers!

    • @Spriteworx
      @Spriteworx  2 ปีที่แล้ว

      Awesome, welcome to the channel! Hope the videos are helpful.