Reverse engineering KERNAL source
Moderator: Moderators
Reverse engineering KERNAL source
It would be useful to have the source for the KERNAL, along with symbol tables and headers for zero page addresses.
I've managed to get dxa to do a reasonable job, I'm now going to need to do some manual cleanup. I've used Compute!'s "Mapping the VIC" for the naming of symbols (with a few minor changes).
Has anyone come across the source for the KERNAL (original or otherwise) or should I proceed and post my copy?
I've managed to get dxa to do a reasonable job, I'm now going to need to do some manual cleanup. I've used Compute!'s "Mapping the VIC" for the naming of symbols (with a few minor changes).
Has anyone come across the source for the KERNAL (original or otherwise) or should I proceed and post my copy?
- Mike
- Herr VC
- Posts: 4840
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Reverse engineering KERNAL source
... which not only gives the KERNAL source (beginning from $E378) but also the complete BASIC interpreter (from $C000 to $E377).
Without such a ROM disassembly, one can pretty much forget about doing things like a BASIC extension or adding extra functionality to the KERNAL like a fast loader for disk drives. The float routines inside BASIC are available at no cost, and their direct use can easily give up to 3 times speed up compared to when called from the interpreter loop ...
Without such a ROM disassembly, one can pretty much forget about doing things like a BASIC extension or adding extra functionality to the KERNAL like a fast loader for disk drives. The float routines inside BASIC are available at no cost, and their direct use can easily give up to 3 times speed up compared to when called from the interpreter loop ...
Last edited by Mike on Sun Aug 10, 2014 10:24 am, edited 1 time in total.
Re: Reverse engineering KERNAL source
That's great. I think I'll update this with the symbols used in the Compute! book.
Re: Reverse engineering KERNAL source
I printed Lee's disassembly out, which meant I could physically draw trace lines through the atrocious CHRIN and CHROUT logic. Even this disassembly has a couple of comments along the lines of 'WTF?' in that code.
Once I'd actually figured-out what the hell they were doing, the substitute routines in FAST-40 came in at about 50% the size and twice as fast.
Once I'd actually figured-out what the hell they were doing, the substitute routines in FAST-40 came in at about 50% the size and twice as fast.
- Mike
- Herr VC
- Posts: 4840
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Reverse engineering KERNAL source
Well? Are there any tangible results you'd want to release?FD22 wrote:Once I'd actually figured-out what the hell they were doing, the substitute routines in FAST-40 came in at about 50% the size and twice as fast.
Re: Reverse engineering KERNAL source
Still working on it - I get maybe a couple of hours a week at the moment.
Here's the core of CHROUT40, for your entertainment and sneak-peek.
Here's the core of CHROUT40, for your entertainment and sneak-peek.
Code: Select all
;; Vector handler for _CHROUT
chrout40 SUBROUTINE character output vector handler [.A, .X, .Y, Stack]
sta _LASTKEY ; [3] ZP save output character
pha ; [3] push output character in .A to Stack
lda _DEVOUT ; [3] ZP get output device
cmp #3 ; [2] output directed to screen device?
beq .screen ; [3/2] jump to screen handler if so
jmp _CHROUT2 ; [6] jump to KERNAL for non-screen output
; output to screen, so FAST-40 handles it
.screen sta _F40CDRAW ; [3] ZP set cursor undraw flag (0=no undraw, !0=undraw)
txa ; [2] save .X and .Y to Stack
pha ; [3]
tya ; [2]
pha ; [3]
; save and disable cursor enable mode (prevent IRQ redrawing cursor mid-way through render)
lda _CRSRMODE ; [3] ZP get cursor enable (0=flash, !0=no flash)
pha ; [3] save to Stack
lda #$FF ; [2]
sta _CRSRMODE ; [3] ZP set cursor enable (0=flash, !0=no flash)
; determine what character we're handling
lda _LASTKEY ; [3] ZP get output character
cmp #$20 ; [2] compare with #32 [SPACE]
bcc .conchar ; [2/3] less than, so a low control character
cmp #$8D ; [2] compare with #141 [SHIFT RETURN]
bcc .normal ; [3/2] less than, so normal printable character
cmp #$A0 ; [2] compare with #160 [INVERSE SPACE]
bcs .normal ; [2/3] not less than, so a normal printable character
; it's a control character, push return address and handler address to Stack
.conchar tax ; [2] shift character to .X for table lookup
lda >#.alldone ; [2] get control character return address hi-byte
pha ; [3] push to Stack
lda <#.alldone-1 ; [2] get control character return address lo-byte
pha ; [3] push to Stack
lda _CONCODEH,x ; [4] get output handler address hi-byte
pha ; [3] push to Stack
lda _CONCODEL,x ; [4] get output handler address lo-byte
pha ; [3] push to Stack
rts ; [6] return to control character handler
; #TODO likely need to do something here when quote mode is on
; it's a normal printable character, output as given
.normal ldy #0 ; [2]
sty _CRSRBLNK ; [3] ZP set cursor blink phase off
sty _F40CDRAW ; [3] ZP set cursor undraw flag (0=no undraw, !0=undraw)
ldy _CURPOS ; [3] ZP get cursor column
sta (_SCRNLINE),y ; [6] write character to text buffer
; set character data address and render masks
tax ; [2] move character to .X for glyph index
lda _CHARTABL,x ; [4] get character glyph data address lo-byte
sta .dataaddr+1 ; [4] modify data read address
lda _CHARTABH,x ; [4] get character glyph data address hi-byte
sta .dataaddr+2 ; [4] modify data read address
lda _F40CMASK ; [3] ZP set character mask
sta .charmask+1 ; [4] set character mask
eor #$FF ; [2] invert it
sta .scrnmask+1 ; [4] set bitmap mask
; merge character data with bitmap
ldy #7 ; [2] glyph bytes to process
.dataaddr lda $C0DE,y ; [4] get character glyph data byte
.charmask and #$FF ; [2] apply character mask
sta .charmrge+1 ; [4] modify character/bitmap merge byte
lda (_F40CADDL),y ; [5] ZP indirect get bitmap byte
.scrnmask and #$FF ; [2] apply screen bitmap mask
.charmrge ora #$FF ; [2] merge glyph byte with bitmap byte
sta (_F40CADDL),y ; [6] ZP indirect set bitmap byte
dey ; [2] decrement glyph byte counter
bpl .dataaddr ; [3/2] loop for next glyph byte
jsr crsrrght ; [6] move cursor after character output
; undraw cursor before calculating new address
.alldone lda _F40CDRAW ; [3] ZP get cursor undraw flag (0=no undraw, !0=undraw)
beq .recalc ; [2/3] skip undraw if not required
lda _CRSRBLNK ; [3] ZP get cursor blink phase flag
beq .recalc ; [2/3] skip undraw if phase is off
jsr drawcrsr ; [6] undraw cursor
; compute new cursor draw address and set blink mask
.recalc ldy _CRSRROW ; [3] ZP get cursor row
ldx _ROWMULT,y ; [4] get multiplied value for bitmap row
lda _CURPOS ; [3] ZP get cursor column
lsr ; [2] divide by two
tay ; [2] shift divided column to .Y
lda #$0F ; [2] set mask for left character (even column)
bcs .setmask ; [3/2] skip switch to right character if odd
lda #$F0 ; [2] column is even so mask for right character
.setmask sta _F40CMASK ; [3] ZP set character mask
txa ; [2] shift multiplied bitmap row to .A
clc ; [2] clear Carry before column addition
adc _COLADDRL,y ; [4] add bitmap column address lo-byte
sta _F40CADDL ; [3] ZP set cursor draw address lo-byte
lda _COLADDRH,y ; [4] get bitmap column address hi-byte
adc #0 ; [2] add Carry
sta _F40CADDH ; [3] ZP set cursor draw address hi-byte
; restore cursor mode
pla ; [4] pull cursor mode from Stack
sta _CRSRMODE ; [3] ZP set cursor enable (0=flash, !0=no flash)
; restore registers, clear error flag in Carry, and exit
pla ; [4] pull .Y, .X and .A from Stack
tay ; [2]
pla ; [4]
tax ; [2]
pla ; [4]
clc ; [2] clear Carry, no error
rts ; [6]
ECHO "chrout40 :",[*-chrout40]d
- Mike
- Herr VC
- Posts: 4840
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Reverse engineering KERNAL source
Yawn.
Here's the *complete* source code of the library used in MG Text Edit, which should be good for some suggestions in case you got stuck with your project.
This program was done in two evenings, on the basis of MINIGRAFIK:
Here's the *complete* source code of the library used in MG Text Edit, which should be good for some suggestions in case you got stuck with your project.
This program was done in two evenings, on the basis of MINIGRAFIK:
Code: Select all
REM>ScreenSrc
:
key=&03
byte=&04
src_ptr=&05
mask_1=&FB
mask_2=&FC
dst_ptr=&FD
:
DIM code 4096
:
FOR pass=4 TO 7 STEP 3
P%=&3000:O%=code
[OPT pass
JMP Init
JMP Main
JMP Kill
.Charset
EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0
EQUB 0:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 0:EQUB 34:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0
EQUB 0:EQUB 85:EQUB 119:EQUB 85:EQUB 85:EQUB 119:EQUB 85:EQUB 0
EQUB 0:EQUB 34:EQUB 51:EQUB 102:EQUB 51:EQUB 102:EQUB 34:EQUB 0
EQUB 0:EQUB 85:EQUB 17:EQUB 34:EQUB 34:EQUB 68:EQUB 85:EQUB 0
EQUB 0:EQUB 102:EQUB 102:EQUB 51:EQUB 102:EQUB 102:EQUB 51:EQUB 0
EQUB 34:EQUB 34:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0
EQUB 0:EQUB 17:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 17:EQUB 0
EQUB 0:EQUB 68:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 68:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 85:EQUB 34:EQUB 85:EQUB 0:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 34:EQUB 119:EQUB 34:EQUB 0:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 34:EQUB 68
EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 119:EQUB 0:EQUB 0:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 34:EQUB 0
EQUB 0:EQUB 17:EQUB 17:EQUB 34:EQUB 34:EQUB 68:EQUB 68:EQUB 0
EQUB 0:EQUB 119:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 119:EQUB 0
EQUB 0:EQUB 17:EQUB 17:EQUB 17:EQUB 17:EQUB 17:EQUB 17:EQUB 0
EQUB 0:EQUB 119:EQUB 17:EQUB 119:EQUB 68:EQUB 68:EQUB 119:EQUB 0
EQUB 0:EQUB 119:EQUB 17:EQUB 119:EQUB 17:EQUB 17:EQUB 119:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 119:EQUB 17:EQUB 17:EQUB 17:EQUB 0
EQUB 0:EQUB 119:EQUB 68:EQUB 119:EQUB 17:EQUB 17:EQUB 119:EQUB 0
EQUB 0:EQUB 119:EQUB 68:EQUB 119:EQUB 85:EQUB 85:EQUB 119:EQUB 0
EQUB 0:EQUB 119:EQUB 17:EQUB 17:EQUB 17:EQUB 17:EQUB 17:EQUB 0
EQUB 0:EQUB 119:EQUB 85:EQUB 119:EQUB 85:EQUB 85:EQUB 119:EQUB 0
EQUB 0:EQUB 119:EQUB 85:EQUB 119:EQUB 17:EQUB 17:EQUB 119:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 34:EQUB 0:EQUB 0:EQUB 34:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 34:EQUB 0:EQUB 0:EQUB 34:EQUB 68
EQUB 0:EQUB 0:EQUB 17:EQUB 34:EQUB 68:EQUB 34:EQUB 17:EQUB 0
EQUB 0:EQUB 0:EQUB 0:EQUB 119:EQUB 0:EQUB 119:EQUB 0:EQUB 0
EQUB 0:EQUB 0:EQUB 68:EQUB 34:EQUB 17:EQUB 34:EQUB 68:EQUB 0
EQUB 0:EQUB 34:EQUB 85:EQUB 17:EQUB 34:EQUB 0:EQUB 34:EQUB 0
EQUB 0:EQUB 51:EQUB 85:EQUB 85:EQUB 85:EQUB 68:EQUB 51:EQUB 0
EQUB 0:EQUB 34:EQUB 85:EQUB 85:EQUB 119:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 102:EQUB 85:EQUB 102:EQUB 85:EQUB 85:EQUB 102:EQUB 0
EQUB 0:EQUB 51:EQUB 68:EQUB 68:EQUB 68:EQUB 68:EQUB 51:EQUB 0
EQUB 0:EQUB 102:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 102:EQUB 0
EQUB 0:EQUB 119:EQUB 68:EQUB 102:EQUB 68:EQUB 68:EQUB 119:EQUB 0
EQUB 0:EQUB 119:EQUB 68:EQUB 102:EQUB 68:EQUB 68:EQUB 68:EQUB 0
EQUB 0:EQUB 51:EQUB 68:EQUB 68:EQUB 85:EQUB 85:EQUB 51:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 119:EQUB 85:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 119:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 119:EQUB 0
EQUB 0:EQUB 51:EQUB 17:EQUB 17:EQUB 17:EQUB 85:EQUB 34:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 102:EQUB 85:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 68:EQUB 68:EQUB 68:EQUB 68:EQUB 68:EQUB 119:EQUB 0
EQUB 0:EQUB 85:EQUB 119:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 102:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 34:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 34:EQUB 0
EQUB 0:EQUB 102:EQUB 85:EQUB 85:EQUB 102:EQUB 68:EQUB 68:EQUB 0
EQUB 0:EQUB 34:EQUB 85:EQUB 85:EQUB 85:EQUB 102:EQUB 51:EQUB 0
EQUB 0:EQUB 102:EQUB 85:EQUB 85:EQUB 102:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 51:EQUB 68:EQUB 34:EQUB 17:EQUB 17:EQUB 102:EQUB 0
EQUB 0:EQUB 119:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 51:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 34:EQUB 34:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 85:EQUB 85:EQUB 119:EQUB 85:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 34:EQUB 85:EQUB 85:EQUB 85:EQUB 0
EQUB 0:EQUB 85:EQUB 85:EQUB 85:EQUB 34:EQUB 34:EQUB 34:EQUB 0
EQUB 0:EQUB 119:EQUB 17:EQUB 34:EQUB 34:EQUB 68:EQUB 119:EQUB 0
EQUB 0:EQUB 51:EQUB 34:EQUB 34:EQUB 34:EQUB 34:EQUB 51:EQUB 0
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ASL src_ptr:ROL A
ASL src_ptr:ROL A
STA src_ptr+1
CLC
LDA src_ptr :ADC #(Charset-32*8) MOD 256:STA src_ptr
LDA src_ptr+1:ADC #(Charset-32*8) DIV 256:STA src_ptr+1
JSR Address:STA mask_2:EOR #&FF:STA mask_1
LDY #7
.Print_00
LDA (dst_ptr),Y:AND mask_1:STA byte
LDA (src_ptr),Y:AND mask_2:ORA byte
STA (dst_ptr),Y:DEY:BPL Print_00
RTS
.Invert
JSR Address:STA mask_1
LDY #7
.Invert_00
LDA (dst_ptr),Y:EOR mask_1:STA (dst_ptr),Y
DEY:BPL Invert_00
RTS
.Address
TXA:LSR A:TAX:PHP
CLC
TYA:ASL A:ASL A:ASL A:ADC Address_01,X:STA dst_ptr
LDA #0 :ADC Address_02,X:STA dst_ptr+1
PLP:LDA #&F0:BCC Address_00:LDA #&0F
.Address_00
RTS
.Address_01
EQUB &00:EQUB &C0:EQUB &80:EQUB &40
EQUB &00:EQUB &C0:EQUB &80:EQUB &40
EQUB &00:EQUB &C0:EQUB &80:EQUB &40
EQUB &00:EQUB &C0:EQUB &80:EQUB &40
EQUB &00:EQUB &C0:EQUB &80:EQUB &40
.Address_02
EQUB &11:EQUB &11:EQUB &12:EQUB &13
EQUB &14:EQUB &14:EQUB &15:EQUB &16
EQUB &17:EQUB &17:EQUB &18:EQUB &19
EQUB &1A:EQUB &1A:EQUB &1B:EQUB &1C
EQUB &1D:EQUB &1D:EQUB &1E:EQUB &1F
.Colour
PHP:PHA
TXA:LSR A:STA Colour_01
TYA:AND #&FE:ASL A:STA Colour_02:ASL A:ASL A:ADC Colour_02:ADC Colour_01:TAY
PLA:PLP
BCC Colour_00
STA &9400,Y
.Colour_00
LDA &9400,Y
RTS
.Colour_01
EQUB 0
.Colour_02
EQUB 0
.Keyboard
LDA &028D:ASL A:CMP #&08:BCC Keyboard_00:LDA #&06
.Keyboard_00
TAX
LDA Keyboard_05,X :STA &F5
LDA Keyboard_05+1,X:STA &F6
LDY &CB:LDA (&F5),Y:TAX
CPY &C5:BEQ Keyboard_01
LDY #&10:STY &028C:BNE Keyboard_03
.Keyboard_01
AND #&7F
BIT &028A:BMI Keyboard_02:BVS Keyboard_04
CMP #&7F :BEQ Keyboard_03
CMP #&14 :BEQ Keyboard_02
CMP #&20 :BEQ Keyboard_02
CMP #&1D :BEQ Keyboard_02
CMP #&11 :BNE Keyboard_04
.Keyboard_02
JMP &EBA1
.Keyboard_03
JMP &EBBA
.Keyboard_04
JMP &EBD6
.Keyboard_05
EQUW Keyboard_06
EQUW Keyboard_07
EQUW &ECE0
EQUW &EDA3
.Keyboard_06
EQUB &31:EQUB &33:EQUB &35:EQUB &37:EQUB &39:EQUB &2B:EQUB &5C:EQUB &14
EQUB &60:EQUB &77:EQUB &72:EQUB &79:EQUB &69:EQUB &70:EQUB &2A:EQUB &0D
EQUB &04:EQUB &61:EQUB &64:EQUB &67:EQUB &6A:EQUB &6C:EQUB &3B:EQUB &1D
EQUB &03:EQUB &01:EQUB &78:EQUB &76:EQUB &6E:EQUB &2C:EQUB &2F:EQUB &11
EQUB &20:EQUB &7A:EQUB &63:EQUB &62:EQUB &6D:EQUB &2E:EQUB &01:EQUB &85
EQUB &02:EQUB &73:EQUB &66:EQUB &68:EQUB &6B:EQUB &3A:EQUB &3D:EQUB &86
EQUB &71:EQUB &65:EQUB &74:EQUB &75:EQUB &6F:EQUB &40:EQUB &5E:EQUB &87
EQUB &32:EQUB &34:EQUB &36:EQUB &38:EQUB &30:EQUB &2D:EQUB &13:EQUB &88
EQUB &FF
.Keyboard_07
EQUB &21:EQUB &23:EQUB &25:EQUB &27:EQUB &29:EQUB &2B:EQUB &7C:EQUB &94
EQUB &7E:EQUB &57:EQUB &52:EQUB &59:EQUB &49:EQUB &50:EQUB &7D:EQUB &8D
EQUB &04:EQUB &41:EQUB &44:EQUB &47:EQUB &4A:EQUB &4C:EQUB &5D:EQUB &9D
EQUB &83:EQUB &01:EQUB &58:EQUB &56:EQUB &4E:EQUB &3C:EQUB &3F:EQUB &91
EQUB &20:EQUB &5A:EQUB &43:EQUB &42:EQUB &4D:EQUB &3E:EQUB &01:EQUB &89
EQUB &02:EQUB &53:EQUB &46:EQUB &48:EQUB &4B:EQUB &5B:EQUB &3D:EQUB &8A
EQUB &51:EQUB &45:EQUB &54:EQUB &55:EQUB &4F:EQUB &7B:EQUB &5E:EQUB &8B
EQUB &22:EQUB &24:EQUB &26:EQUB &28:EQUB &30:EQUB &5F:EQUB &93:EQUB &8C
EQUB &FF
.IRQ
CLD
LDX #&00
INC &A2:BNE IRQ_00
INC &A1:BNE IRQ_00
INC &A0
.IRQ_00
LDA &A1:CMP #&1A:LDA &A0:SBC #&4F:BCC IRQ_01
STX &A0:STX &A1:STX &A2
.IRQ_01
LDX IRQ_03:INX:CPX #40:BCC IRQ_02:LDX #0
.IRQ_02
STX IRQ_03:JMP &EAC2
.IRQ_03
EQUB 0
.Norm
LDA &900F:AND #8:BEQ Norm_00
RTS
.Norm_00
LDA &900F:ORA #8:STA &900F
LDA #&00:STA &FD:TAX
LDA #&11:STA &FE
.Norm_01
LDA &9400,X:AND #8:BNE Norm_03
LDY #0
.Norm_02
LDA (&FD),Y:EOR #&FF:STA (&FD),Y
INY:CPY #16:BNE Norm_02
.Norm_03
CLC
LDA &FD:ADC #&C0:STA &FD
LDA &FE:ADC #&00:STA &FE
CMP #&20:BCC Norm_04
LDA &FD:SBC #&F0:STA &FD
LDA &FE:SBC #&0E:STA &FE
.Norm_04
INX:CPX #240:BNE Norm_01
RTS
.Cursor
LDX Cursor_06:LDY Cursor_07:CLC:JSR Colour:STA Cursor_08
LDA #0:STA IRQ_03
.Cursor_00
LDA &0286:JSR Cursor_03
.Cursor_01
LDA IRQ_03:CMP #20:BCS Cursor_04
JSR &FFE4:STA key:BEQ Cursor_01
.Cursor_02
LDA Cursor_08
.Cursor_03
LDX Cursor_06:LDY Cursor_07:SEC:JSR Colour
LDX Cursor_06:LDY Cursor_07:JMP Invert
.Cursor_04
JSR Cursor_02
.Cursor_05
LDA IRQ_03:CMP #20:BCC Cursor_00
JSR &FFE4:STA key:BEQ Cursor_05:RTS
.Cursor_06
EQUB 0
.Cursor_07
EQUB 0
.Cursor_08
EQUB 0
.Right
LDX Cursor_06:LDY Cursor_07:INX:CPX #40:BCC Right_00
LDX #39:CPY #23:BCS Right_00:LDX #0:INY
.Right_00
STX Cursor_06:STY Cursor_07:RTS
.Left
LDX Cursor_06:LDY Cursor_07:DEX:CPX #40:BCC Left_00
LDX #0:CPY #1:BCC Left_00:LDX #39:DEY
.Left_00
STX Cursor_06:STY Cursor_07:RTS
.Down
LDY Cursor_07:CPY #23:BCS Down_00:INY
.Down_00
STY Cursor_07:RTS
.Up
LDY Cursor_07:CPY #1:BCC Up_00:DEY
.Up_00
STY Cursor_07:RTS
.Init
JSR Norm
LDA #0:STA Cursor_06:STA Cursor_07
LDA &900F:LSR A:LSR A:LSR A:LSR A:TAX:LDA Init_00,X:STA &0286
SEI
LDA #Keyboard MOD 256:STA &028F
LDA #Keyboard DIV 256:STA &0290
LDA #IRQ MOD 256:STA &0314
LDA #IRQ DIV 256:STA &0315
CLI
RTS
.Init_00
EQUB 1:EQUB 0:EQUB 1:EQUB 0:EQUB 1:EQUB 0:EQUB 1:EQUB 0
EQUB 1:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0:EQUB 0
.Main
JSR Cursor:LDA key
CMP #32:BCC Main_01
CMP #127:BCS Main_01
LDX Cursor_06:LDY Cursor_07:JSR Print
LDA &0286:LDX Cursor_06:LDY Cursor_07:SEC:JSR Colour
LDA &C7:BEQ Main_00
LDX Cursor_06:LDY Cursor_07:JSR Invert
.Main_00
JSR Right:JMP Main
.Main_01
CMP #5 :BEQ Main_02
CMP #18 :BEQ Main_02
CMP #28 :BEQ Main_02
CMP #30 :BEQ Main_02
CMP #31 :BEQ Main_02
CMP #144:BEQ Main_02
CMP #146:BEQ Main_02
CMP #156:BEQ Main_02
CMP #158:BEQ Main_02
CMP #159:BNE Main_03
.Main_02
JSR &FFD2:JMP Main
.Main_03
CMP #29 :BNE Main_04:JSR Right:JMP Main
.Main_04
CMP #157:BNE Main_05:JSR Left :JMP Main
.Main_05
CMP #17 :BNE Main_06:JSR Down :JMP Main
.Main_06
CMP #145:BNE Main_07:JSR Up :JMP Main
.Main_07
CMP #13 :BNE Main_08:LDA #0:STA Cursor_06:JSR Down:JMP Main
.Main_08
CMP #19 :BNE Main_09:LDA #0:STA Cursor_06:STA Cursor_07:JMP Main
.Main_09
RTS
.Kill
SEI
LDA #&DC:STA &028F
LDA #&EB:STA &0290
LDA #&BF:STA &0314
LDA #&EA:STA &0315
CLI
RTS
]
NEXT
Re: Reverse engineering KERNAL source
I... I don't know what to say. You passively-aggressively asked for some proof that I'm not bullshitting when I talk about something I've done that's relevant to the OP, so I showed you some real code I've written. You actually type the word 'yawn', which is just not remotely interpretable as a language/culture misalignment but is simply plain insulting.
You go on to boast that you managed to write all the (uncommented, impenetrable) code you then posted in just two nights, deriding my note about having little time to work on my project. Well, I'm really pleased for you that you live in a world where work, family life, and adult commitments don't detract from your project time.
And you then not-very-subtly imply that I could use your code as a basis for something I might be 'stuck on', even though I hadn't mentioned being stuck on anything or indeed in need of help in any way. Magnanimous, in an 'alms to the poor' way. Thanks, but no thanks.
You know what the worst thing is? You're really clever. You do stuff I find interesting, your technical posts are always the ones I look for in the Programming and Emulation threads, and on one occasion in the distant past I've even posted a question here about debugging the KERNAL to which your answer did in fact provide a vital clue that got me out of a hole. The trouble is, there's always a degree of apprehension when I click the link - will Mike just write something interesting, or will he taint it by being condescending in some way?
So, with apologies to the OP and indeed the rest of the community here for this contretemps, I'd like to make a deal with you, Mike. You refrain from commenting on my posts, and I'll do the same for you. I've desperately tried to maintain an even temper in all the threads we've co-habited, even when you've done your best to bait me, but I'm afraid you've crossed the line tonight and, whilst I'll continue to read what you write with interest, I'd prefer it if from here on we simply co-existed rather than interacted.
You go on to boast that you managed to write all the (uncommented, impenetrable) code you then posted in just two nights, deriding my note about having little time to work on my project. Well, I'm really pleased for you that you live in a world where work, family life, and adult commitments don't detract from your project time.
And you then not-very-subtly imply that I could use your code as a basis for something I might be 'stuck on', even though I hadn't mentioned being stuck on anything or indeed in need of help in any way. Magnanimous, in an 'alms to the poor' way. Thanks, but no thanks.
You know what the worst thing is? You're really clever. You do stuff I find interesting, your technical posts are always the ones I look for in the Programming and Emulation threads, and on one occasion in the distant past I've even posted a question here about debugging the KERNAL to which your answer did in fact provide a vital clue that got me out of a hole. The trouble is, there's always a degree of apprehension when I click the link - will Mike just write something interesting, or will he taint it by being condescending in some way?
So, with apologies to the OP and indeed the rest of the community here for this contretemps, I'd like to make a deal with you, Mike. You refrain from commenting on my posts, and I'll do the same for you. I've desperately tried to maintain an even temper in all the threads we've co-habited, even when you've done your best to bait me, but I'm afraid you've crossed the line tonight and, whilst I'll continue to read what you write with interest, I'd prefer it if from here on we simply co-existed rather than interacted.
- Mike
- Herr VC
- Posts: 4840
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Reverse engineering KERNAL source
Indeed, I got bored. You keep talking about your projects with no hint about when they might surface. When not too subtly hinted at that fact, you instead repeat your pattern of going personal and/or talking about language barriers.FD22 wrote:I... I don't know what to say. You passively-aggressively asked for some proof that I'm not bullshitting when I talk about something I've done that's relevant to the OP, so I showed you some real code I've written. You actually type the word 'yawn', which is just not remotely interpretable as a language/culture misalignment but is simply plain insulting.
Didn't you think posting an already-too-long snippet of boilerplate code by yourself did equally qualify as boasting?You go on to boast that you managed to write all the (uncommented, impenetrable) code you then posted in just two nights, deriding my note about having little time to work on my project. Well, I'm really pleased for you that you live in a world where work, family life, and adult commitments don't detract from your project time.
There's a lot of side documentation for my code I didn't bother to add in. I did not expect of you, or anyone else to grasp that library code within one hour or so.
Your code also is effectively uncommented and impenetrable for anyone who is not remotely deep into the internals of the KERNAL. Cycle counts are of no relevance here. Line by line comments of assembly code don't give anything - there's no use to comment instructions with the equivalence of 'i++; // increment i'. More useful would be to add several lines of comments before each bigger block of instruction that does a coherent action.
Yet, at the end of the paragraph you again mix in your assumptions about my personal life. I won't comment further on this.
A glimpse over your blog told me otherwise. It read like a recipe to research what could go wrong. Interrupt routines hanging, a cursor leaving trails around, etc. Then, complaining about how difficult all this is. A constant urge to reinvent the wheel. Turning down offers to make this work. Not wanting to read others code. Not wanting to have to credit others for ideas taken from their code.And you then not-very-subtly imply that I could use your code as a basis for something I might be 'stuck on', even though I hadn't mentioned being stuck on anything or indeed in need of help in any way. Magnanimous, in an 'alms to the poor' way. Thanks, but no thanks.
No wonders that gets you nowhere. When it comes to releasing working programs for the VIC-20, that is.
That was at the time you posted as MRaider here, I know. Here's the thread in question. Unfortunately, that account and all the posts of that account have been deleted, making a lot of threads incomprehensible. You stopped using that account, shortly after we had a discussion about ways of representing source code in the forum, where we couldn't get to equal terms.You know what the worst thing is? You're really clever. You do stuff I find interesting, your technical posts are always the ones I look for in the Programming and Emulation threads, and on one occasion in the distant past I've even posted a question here about debugging the KERNAL to which your answer did in fact provide a vital clue that got me out of a hole. The trouble is, there's always a degree of apprehension when I click the link - will Mike just write something interesting, or will he taint it by being condescending in some way?
Then already you resorted to personal attacks, which forced me to leave a neutral position regarding your manners. I also suspected you made it easy for yourself going against my moderation job, with you hoping the implied neutrality demanded of that moderator job might make it difficult for me to defend myself against your allegations. Well, I didn't do you the favour and instead turned down my moderator job.
When you reappeared here as FD22, it didn't take me very long to recognize you again. Yet, everyone deserves a second chance ...
I agree that the discussion at this point doesn't bring forward the original topic of the thread anymore.So, with apologies to the OP and indeed the rest of the community here for this contretemps, I'd like to make a deal with you, Mike. You refrain from commenting on my posts, and I'll do the same for you. I've desperately tried to maintain an even temper in all the threads we've co-habited, even when you've done your best to bait me, but I'm afraid you've crossed the line tonight and, whilst I'll continue to read what you write with interest, I'd prefer it if from here on we simply co-existed rather than interacted.
Beginning with my question about the state of your project, these posts could be split into another thread.
And, I'm afraid, the easy solution you'd prefer is not going to happen. What goes around, comes around.
Re: Reverse engineering KERNAL source
The VIC 20 is indeed the friendly computer! Denial strives to be an equally friendly forum. I hope all can choose to carry on with respectful and pleasant intentions.