Login
Forum Help



Post Your Message
Username: (Login)

Topic:
Message:
 


Previous Messages
Posted By

JamesD
on 2017-11-28
20:36:48
 Re: Patch for BASIC to make it faster?

I was running some benchmarks and the horribly slow times indicated it was doing just what it's doing. Way too much to read a byte.


FWIW, the CHARGET and CHARGOT can be patched without doing anything to the ROM.
Just replace the code with the patched version that removes the interrupt disable, switch in RAM, and then switches in ROM, and enables interrupts after reading 1 byte.
But you can't do it from BASIC.
You also need to patch the pointers to the top of memory and things like that, but it's not difficult code.


This is the section of ROM. The disassembly is pretty incomplete so I don't know if you can patch get under ROM or not. I'm not sure what uses it.
The functions are at the following addresses in RAM.
CHRGET equ $0473 ; get byte from basic ( incs LastBasicLineNo first )
CHRGOT equ $0479 ; gets current byte from basic (doesn't inc LastBasicLineNo )


----------------------------------------------------------------------------------------------------------
;
; CHRGET/CHRGOT - This chunk of code is copied to RAM
; and run from there. It is used to get data UNDER the
; system ROM's for basic.
;
; CHRGET ($0473)
L8123 INC LastBasicLineNo ; $3b (goes to $0473 ) CHRGET
BNE L8129
INC LastBasicLineNo+1 ; $3c
;
; CHRGOT ($0479)
;
L8129 SEI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
STA RAM_ON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
LDY #$00
LDA (LastBasicLineNo),y ; $3b
STA ROM_ON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
CLI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
CMP #$3A ; ":" (colon)
BCS L8143 ; if colon, exit
CMP #$20 ; " " (space)
BEQ L8123 ; if space, get NEXT byte from basic
SEC
SBC #$30
SEC
SBC #$D0
L8143 RTS

L0494 STA $049C ; set location to get byte from.

;
; This section gets copied to $04A5
;
GetUnderROM
SEI ; IRQ's off <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
STA RAM_ON ; DISABLE ROM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
LDA ($00),y ; get byte ($00 is at location $49C)
STA ROM_ON ; enable ROM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
CLI ; IRQ's on again.. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
RTS ; and return...

db $00,$00,$00
-------------------------------------------------------------------------------------------------------------



Rough code for the patch. Unfinished.

SEI
;Set up new pointers here

;copy new CHARGOT routine over old one
LDX #21 ; Copy down NEWCHRGOT
L804C LDA NEWCHARGOT,x ; routines. These are used for
STA $0479,x ; fetching data under the system
DEX ; ROM
BNE L804C
CLI
;return to BASIC here.


ORG $0479 ;assemble for target address, then db the resulting bytes as part of above program
;
; CHRGOT ($0479)
;
NEWCHARGOT
LDY #$00
LDA (LastBasicLineNo),y ; $3b
CMP #$3A ; ":" (colon)
BCS EXIT ; if colon, exit
CMP #$20 ; " " (space)
BEQ $0473 ; if space, get NEXT byte from basic
SEC
SBC #$30
SEC
SBC #$D0
EXIT
RTS







Posted By

KiCHY
on 2017-11-28
02:44:37
 Re: Patch for BASIC to make it faster?

PAL (YAPE 1.1.5, hacked):
Normal screen: 7069
Reduced screen: 7069
Screen off: 4710

NTSC (YAPE 1.1.5, hacked, "morphed from PAL to NTSC"):
Normal screen: 9368
Reduced screen: 9369
Screen off: 5631

All I have is a YAPE snapshot, which contains the copied+modified ROM/RAM, basic memory truncated to $8000, ROM turned off, plus a prompt to write BASIC stuff. If anyone needs it, I can send by email, or upload somewhere.

Posted By

JamesC
on 2017-11-27
20:57:42
 Re: Patch for BASIC to make it faster?

SVS noted a few months ago that BASIC banks in RAM even when the needed byte(s) are below $8000:
forum/34019

Just for grins and giggles, I wondered how much speed we might gain by shrinking the screen from 40x25 to 38x24 (assuming that the CPU would go to 2x speed slightly more per video frame).

It turns out that we don't gain a thing by this.

PAL (using YAPE 1.1.5, 100% speed 50fps):
Normal screen: 8371 jiffies to count from 0 to 100,000
Reduced screen: 8371 jiffies
Screen blanked: 5578 jiffies

NTSC (100% speed 60fps):
Normal screen: 9229 jiffies
Reduced screen: 9229 jiffies
Screen blanked: 5552 jiffies

5 PRINT"COUNTING..."
10 TI$="000000":FOR X= 0 TO 100000:NEXT
20 A = TI
30 PRINT CHR$(27)"R"
40 POKE65286,PEEK(65286)AND247
41 POKE65287,PEEK(65287)AND247
45 PRINT"COUNTING AGAIN..."
50 TI$="000000":FOR X= 0 TO 100000:NEXT
60 B = TI
70 POKE65286,PEEK(65286)OR8
71 POKE65287,PEEK(65287)OR8
80 PRINTCHR$(27)"N"
90 P=PEEK(65286):POKE65286,0
100 TI$="000000":FOR X= 0 TO 100000:NEXT
110 C=TI
120 POKE65286,P
130 PRINT"FULL SCREEN:";A :PRINT"REDUCED SCREEN:";B :PRINT"SCREEN OFF:";C

Kichy, how much speed might we gain if the garbage collection routine mimics how it's done on the C64?

Posted By

MMS
on 2017-11-27
15:45:22
 Re: Patch for BASIC to make it faster?

OK, thanks for clarification!

Yeah, I really misunderstood the sentence. "Using only RAM below ROM" for me meant we copy the ROM into RAM, and do not use the ROM at all, and no bank switching. (as they are paralell above $8000)
I blame the two beers happy

I remember that the RAM has some speed benefits over ROM, but maybe it is valid only in modern PCs (that's why you can set your BIOS settings to copy at the startup the BIOS from EPROM into RAM, and execute it from there).

(and I saw in a test, that C128 BASIC execution was even slower (with the same commands) than our one most pobably due to intensive bank switching.)

Posted By

Csabo
on 2017-11-27
14:57:08
 Re: Patch for BASIC to make it faster?

"What is the real difference between ROM and RAM speed?" Nothing, I think you might not be clear on what's exactly happening. (Also... I swear we talked about this a while back.)

Anyway, the "speed" or RAM/ROM is the same. What changes here is how the BASIC programs are being run: it routinely does RAM/ROM swapping. (It must; since the BASIC programs can be above $8000 in the RAM, but the code that executes those BASIC programs is on the same location; above $8000 in the ROM.)

If the programs are short, as JamesD pointed out in the first post, this could be eliminated, ROM can be selected at all times. So, less paging = less operations = speed gain. It's clever, but not that spectacular really IMHO, and I do think that the values Kichy just posted are representative of what can be expected.

Posted By

MMS
on 2017-11-27
15:00:36
 Re: Patch for BASIC to make it faster?

Really nice idea! What is the real difference between ROM and RAM speed?

I suppose the FOR is just too simple command to show this method's full potentials.
Maybe in case of the GFX commands (CIRCLE combined with FOR, as lot of calculations inside) could show the real difference. Or what else?

Posted By

KiCHY
on 2017-11-27
12:38:29
 Re: Patch for BASIC to make it faster?

I made some quick experiments. I copied ROM to RAM, modified the JSRs to LDA, etc. and tested with the following basic program:
10 TI$="000000"
20 FORJ=0to100000:NEXTJ
30 PRINTTI$

Result (original, hacked):
"FORJ=0to10000" -> (00:00:16, 00:00:14)
"FORJ=0to100000" -> (00:02:52, 00:02:23)

Posted By

SVS
on 2017-11-27
11:48:58
 Re: Patch for BASIC to make it faster?

I remember many (many!) years ago there was a utility (written by RDG if I'm not wrong) that copied all the ROM content into RAM. The banking routines were patched in order to always read from RAM.
This was made in order to easy modify the O.S. (for example changing the system messages).
Anyway I don't think it was faster for Basic exec.

Posted By

KiCHY
on 2017-11-27
02:25:18
 Re: Patch for BASIC to make it faster?

I just thought about this a few days ago. I found two kind of patches.
- The first patch seems easy: POKE some zeropage values to tell basic to store variables under $8000, another POKEs modify the RAM reading function(s) after $0470. A basic program can do these modifications.
- The second patch is to modify ROM: modify The paging functions to be copied in ROM. We can't patch JSR$0473 and JSR$0479 calls, we can't replace 3 bytes with 4 bytes (LDY #0; STA ($xy),Y). And for second step, we have to patch that ROM routine which initializes those zero page pointers (basic top, variables, etc.)

Posted By

JamesD
on 2017-11-26
14:48:16
 Patch for BASIC to make it faster?

Just curious to see if anyone has tried patching BASIC so it only uses RAM below ROM so smaller programs can run faster.


Copyright © Plus/4 World Team, 2001-2024