Close

Creating GPTs of Z80 Specialist

A project log for MIDI Interface for RC2014

Building MIDI Interface for RC2014. The goal of this project is to build a music system with RC2014 computer and external (legacy) MIDI box

morecatlabmorecat_lab 10/07/2024 at 07:400 Comments

Creating GPTs of Z80 Specialist

1. Motivation

Large Language Models (LLMs), such as ChatGPT, generate programs based on information available on the internet, utilizing language models. For example, if you request it to create a "Hello World" program for CP/M, it will generate a reasonably functional program.

        ORG     100h                ; CP/M programs start at 100h
        LD      DE, message         ; Load the address of the message into DE
        LD      C, 9                ; BDOS function 9 (print string)
        CALL    5                   ; Call BDOS

        RET                         ; Return to CP/M

message:
        DB      'Hello, World!$'    ; Message to print, ending with a '$'

 
However, since LLMs do not possess specialized knowledge, if you ask them to create a "Hello World" using the SCM API, the generated program may look somewhat suspicious.

        ORG     100h                ; Start of the program

        LD      HL, message         ; Load address of the message into HL

print_loop:
        LD      A, (HL)             ; Load the current character into A
        CP      0                   ; Check if it's the null terminator (0x00)
        JP      Z, end               ; If zero, end the program

        CALL    0005h               ; Call SCM routine to print a character
        INC     HL                  ; Move to the next character in the string
        JP      print_loop          ; Repeat the loop

end:
        RET                         ; Return to monitor

message:
        DB      'Hello, World!', 0   ; Message string terminated by 0x00

 
This happens because the model is relying on general knowledge to generate its answers. By using specialized knowledge, we could likely obtain more refined results.

2. Programming Assistant for Small Computer Monitor (Z80)

To emphasize specialized knowledge and obtain better answers, I decided to create a custom GPT. GPTs can change the policy for generating responses. In this case, I instructed it to refer to the SCM reference manual and user manual when creating programs.


The prompt I provided was as follows:

This GPT is designed to be a programming assistant for working with 
Z80, an 8-bit microprocessor commonly used in vintage computing and 
embedded systems. It helps users write, debug, and optimize assembly 
code for small computer monitors or other Z80-based systems. It will 
refer SCM user guide and reference manual in knowledge area. It offer
 practical tips, explanations, and sample code, adapting to the user's 
knowledge level. The assistant stays focused on Z80 programming tasks, 
providing guidance on registers, memory management, instruction sets,
 and general programming flow in Z80 assembly. It ensures clarity in
 all interactions while avoiding unnecessary jargon.

 As intended, it successfully created a program using the SCM API.

    ORG 0x8000           ; Start the program at 0x8000 (example address)

    LD HL, message       ; Load the address of the message into HL
print_loop:
    LD A, (HL)           ; Load the current character into register A
    CP  '$'              ; Check if the character is the string terminator ('$')
    JR Z, end_print      ; If the character is '$', jump to end the print loop
    CALL api_print_char  ; Call the SCM API function to print the character
    INC HL               ; Move to the next character in the string
    JR print_loop        ; Repeat the loop for the next character

end_print:
    CALL api_newline     ; Print a new line using SCM API
    RET                  ; Return to SCM

message:
    DB 'Hello, World!$'  ; Message string terminated with '$'

; SCM API calls
api_print_char:
    LD C, 2              ; SCM API function $02: output character
    CALL 0x0030          ; SCM API handler
    RET

api_newline:
    LD C, 7              ; SCM API function $07: output newline
    CALL 0x0030          ; SCM API handler
    RET

RTS $30 is batter for API call. 

You can access the prototype GPTs from here.

Programming Assistant Small Computer Monitor (Z80)

Discussions