Custom ROM Kernal

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Custom ROM Kernal

Post by mythic66 »

Hi,

I'm struggling to make my program boot, here's the detail. I wrote a simple program, bare metal, using no Kernal routines, to print a string at the screen. ORG is at $1001 for testing purpose. Works perfectly in VICE for Unexp VIC.

I then change the ORG for $E000, make a 8192 byte bin file, set FFFC and FFFD to $E000 in the file

I then tried to replace the kernal file in vice by mine, no joy for the execution. I also tried to burn an eprom to try on a real VIC20, still no boot.

The program init the vic chip, then print directly to the VRAM a short string. No interrupt is use, no fancy here.

Any hint ?
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Custom ROM Kernal

Post by srowe »

Did you duplicate the VIC setup code? There's a table of register values that are used to initialize the VIC registers, without that it won't display the expected 22*23 screen positioned correctly, and most importantly, be looking at $1E00 for your data.
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Re: Custom ROM Kernal

Post by mythic66 »

yes, as stated, I init the VIC chip, each of its register are configured properly.

I suspect something with the reset vector and/or other vectors, but they are imo, configured correctly.

Code: Select all

VICREG          byte $04        ;$9000 - horizontal centering
                byte $19        ;$9001 - vertical centering
                byte $96        ;$9002 - set # of columns / 
                                ;Bit7 = screen base bit ($16 for screen at $1000)
                byte $AE        ;$9003 - set # of rows
                byte $7A        ;$9004 - TV raster beam line
                byte $F0        ;$9005 - bits 0-3 start of character memory /  
                                        
                byte $00        ;$9006 - horizontal position of light pen
                byte $01        ;$9007 - vertical position of light pen
                byte $FF        ;$9008 - Digitized value of paddle X
                byte $FF        ;$9009 - Digitized value of paddle Y
                byte $00        ;$900A - Frequency for oscillator 1 (low)
                byte $00        ;$900B - Frequency for oscillator 2 (medium)
                byte $00        ;$900C - Frequency for oscillator 3 (high)
                byte $00        ;$900D - Frequency of noise source
                byte $00        ;$900E - bit 0-3 sets volume of all sound / 
                                ;bits 4-7 are auxiliary color information
                byte %00001000  ;$900F - Screen and border color register
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Custom ROM Kernal

Post by Mike »

mythic66,

please do the people reading this thread and trying to help a favour and post the source, or at least the KERNAL binary file you built. Without any of them, any speculations about the reasons why the code fails are only that: speculations.

Besides, code that is just supposed to print a message on screen, bare-bones, without any KERNAL assistance still can't be that involved so you could have a reasonable interest not to disclose it.

Greetings,

Michael
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Re: Custom ROM Kernal

Post by mythic66 »

Mike,

There's nothing secret there !, just a quick program for testing purpose. It's not been optimized at all

Code: Select all

;******************************************************************************
defm PrnScr
                
                lda #/3                
                sta VPTR                ; Init video ram pointer
                sta CPTR
                lda #/2
                sta VPTR+1
                clc
                adc #$78                ; Init color ram pointer
                sta CPTR+1
                lda #0
                sta LROW;

                ldy #0
                ldx #0
@loopR0         lda /1,x                ; Load buffer
                beq @exit               ; buffer end  0?
                cmp #$A0                ; Line feed?
                bne @loopR1             ; no
                
                lda LROW                ; LineFeed subroutine
                clc
                adc #$16
                bcs @xloop0             ; Over $FF
                sta LROW
                tay
                inx
                jmp @loopR0;

@xloop0         sta LROW                ; second part of the screen
                tay
@xloop1         lda #$1F
                sta VPTR+1
                lda #$97
                sta CPTR+1
                inx
                jmp @loopR0             ;----------------------           
                
@loopR1         sta (VPTR),y            ; Print Char
                lda #/4
                sta (CPTR),y            ; Color Char
                iny
                beq @xloop1
                inx
                jmp @loopR0;

@exit           nop

                endm
               

;******************************************************************************
; Basic STUB
;******************************************************************************



*=$E000

         

      ;  byte $0C, $10, $DC, $07, $9E, $20, $34, $31, $31, $30, $00, $00, $00


   
;******************************************************************************
; Main routine
;******************************************************************************                                       

Main                              
        
                jsr VicInit
                
                jsr ROMenu

Exit            rts

        
;******************************************************************************
; ROM
;******************************************************************************

ROMenu
                jsr ClrScr
                
                PrnScr TOPBOX1,$1E,$CA,#6       ; Box
                PrnScr SCRA0,$1E,$E3,#4         ; Title

ROMexit         rts


;******************************************************************************
; Clear screen routine
;******************************************************************************

ClrScr
                ldx #0
loopC0          lda #$20
                sta $1E00,x
                lda $01
                sta $9600,x
                inx
                bne loopC0

loopC1          lda #$20
                sta $1E00+255,x
                lda $01
                sta $9600+255,x
                inx
                cpx #$FB
                bne loopC1       
 
                rts
        
;******************************************************************************
; VIC chip initialisation
;******************************************************************************

VicInit
                ldx #0                                 
        
loopV0          lda VICREG,x                 
                sta $9000,x 
                inx                            
                cpx #16
                bne loopV0
 
                rts

;******************************************************************************
; Const and variables
;******************************************************************************

VICREG          byte $04        ;$9000 - horizontal centering
                byte $19        ;$9001 - vertical centering
                byte $96        ;$9002 - set # of columns / 
                                ;Bit7 = screen base bit ($16 for screen at $1000)
                byte $AE        ;$9003 - set # of rows
                byte $7A        ;$9004 - TV raster beam line
                byte $F0        ;$9005 - bits 0-3 start of character memory /  
                                        
                byte $00        ;$9006 - horizontal position of light pen
                byte $01        ;$9007 - vertical position of light pen
                byte $FF        ;$9008 - Digitized value of paddle X
                byte $FF        ;$9009 - Digitized value of paddle Y
                byte $00        ;$900A - Frequency for oscillator 1 (low)
                byte $00        ;$900B - Frequency for oscillator 2 (medium)
                byte $00        ;$900C - Frequency for oscillator 3 (high)
                byte $00        ;$900D - Frequency of noise source
                byte $00        ;$900E - bit 0-3 sets volume of all sound / 
                                ;bits 4-7 are auxiliary color information
                byte %00001000  ;$900F - Screen and border color register




LROW            byte $00        ; last row
VPTR                =$FB        ; ZP Video pointer
CPTR                =$FD        ; ZP Color pointer

;******************************************************************************
; Menu Box
;******************************************************************************

TOPBOX1 byte $55,$43,$43,$43,$43,$43,$43,$43,$43,$43,$43,$43,$43,$49,$A0
        byte $42,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$48,$A0
        byte $4A,$46,$46,$46,$46,$46,$46,$46,$46,$46,$46,$46,$46,$4B,0

 
SCRA0   text 'test rom',$A0,$A0,0

;*****

*=$FFFC

        byte <Main, >Main
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Custom ROM Kernal

Post by Mike »

The two LDA $01 (ZP address mode) in the loops loopC0 and loopC1 are in error and quite likely should instead be LDA #$01 (immediate address mode) to load white (=1) as value for the colour RAM.

"/1", etc. look somewhat non-standard syntax for me. What are they supposed to do?

Finally, it should go without saying that you can't hold mutable values (i.e. variables) in ROM. STA LROW won't succeed.
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Re: Custom ROM Kernal

Post by mythic66 »

Mike wrote: Sun Feb 26, 2023 7:46 am The two LDA $01 (ZP address mode) in the loops loopC0 and loopC1 are in error and quite likely should instead be LDA #$01 (immediate address mode) to load white (=1) as value for the color RAM.

"/1", etc. look somewhat non-standard syntax for me. What are they supposed to do?

Finally, it should go without saying that you can't hold mutable values (i.e. variables) in ROM. STA LROW won't succeed.
Thanks for the reply, I'll correct the errors.

the " /1 " is the argument given to the macro when I call it.

Hmm, totally agree about the variables, nooby error.. :roll:
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

Re: Custom ROM Kernal

Post by mythic66 »

After some head scratching, I found the problem. I had to put NOLOADADDRESS at the beginning so the compiler don't add the ORG address at the beginning of the bin file.

Works great ! :mrgreen:
pic1.png
pic2.png
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: Custom ROM Kernal

Post by MrSterlingBS »

Hello,

Is there a guide here in the forum for creating a ROM?
I would integrate this into VICE.

BR
Sven
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Custom ROM Kernal

Post by srowe »

MrSterlingBS wrote: Wed Jun 28, 2023 2:46 am Is there a guide here in the forum for creating a ROM?
I would integrate this into VICE.
Replacing the KERNAL ROM used by vice is as simple as running it with

Code: Select all

xvic -kernel my-rom.bin
The file must be a plain binary, not a .PRG with the load address at the front.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Custom ROM Kernal

Post by Mike »

MrSterlingBS wrote:I would integrate this into VICE.
As srowe already wrote, providing a binary image without load address with a (file) size of exactly 8192 bytes most probably is the least of problems. For that matter, the VICE UI also provides a dialog box to specify the files to be used as BASIC, KERNAL or Character ROM (the latter is only 4096 bytes in length).
Is there a guide here in the forum for creating a ROM?
It is rather easy to customize the existing KERNAL for own screen colours and start-up message. Anything beyond that (up to designing an own OS from scratch) is likely beyond what could be conveyed in a guide or tutorial. As a starter, you might want to answer yourself the question why I used the following instruction sequence in my fix of the multiplication routine:

Code: Select all

[...]
.DF6A  A0 01     LDY #$01
.DF6C  98        TYA
.DF6D  4A        LSR A
.DF6E  85 26     STA $26
[...]
... instead of the much simpler (but wrong!) sequence LDA #$00 / STA $26.

See also this post and this other post, and to quote from the latter:
Mike wrote:[...] all [machine code and] table data could be somehow be referenced by some 3rd party program. There is no abstraction layer whatsoever (the KERNAL jump table being a honorable exception) which would help here [...] if you begin to change the ROMs, you just enter a continuum where more and more programs fail, in proportion to the amount of changed code. [...]
Post Reply