Commodore‎ > ‎C128‎ > ‎

2MHz-Border

It has been said that the Commodore 128 is both the fastest and the slowest of all CBM 8-bit computers!


  Bendevil BASIC Test  

To test that, below is a simple "test" program (by BenDevil) written in BASIC 2.0... in other words it will run on any CBM machine (except the very original/prototype PETs).

10 T=TI
20 A=2
30 FOR I=1 TO 20
40 A=SQR(A)
50 NEXT I
60 FOR I=1 TO 20
70 A=A*A
80 NEXT I
90 PRINT "A=";A
100 PRINT "TIME=";TI-T

Try running that on your favorite Commodore, or any good emulator.  Hopefully you will see that on the C128 (in default "slow" mode) is slower than any other 8-bit CBM (like the famous C64).  On the other hand, if you issue the BASIC command "FAST", then running the same program will give a "speed" faster than any other 8-Bit CBM (yes, faster than C64).

However, most of us know that FAST / 2MHz speed only works (by default) when used with the 80-column VDC screen.  If you try to use FAST with 40-column (VIC-II / C64-compatible) video screen, then there is no display (the VIC is disabled at 2MHz).


  Hydro's Quick Hack  

The following is a very simple/lame wedge for 40-column / VIC users... It enables FAST (2MHz) speed during the VIC "border"... the CPU runs at "slow" (1MHz) speed while VIC displays the "active" screen (active graphics between the borders).  FYI, the following code is my original work (used by me for many years), but I am not the first/only person to do this... many commercial programs also used the 2MHz-Border trick (for example "Gunship" by MicroProse).

; ** 2MHZ Border **
;Enable FAST (2MHz) speed on the Commodore 128 (C128) during VIC-IIe border
;Copyright Robert Willie (hydrofilic@hotmail.com) 1988, 1992, 2003, 2005, 2009, 2010, 2011, 2013, 2014, 2015
;Free to use by everbody with attribution!

loadAdrs	= $1700
fastRaster	= 251	;(1 raster beyond visible screen)


;---- the code ------
.text	;segment

*=loadAdrs-2		;ORG
	.byte loadAdrs
	
	jmp Install
	jmp Remove
	
iIRQ = $314
oIRQ	.word 0		;hold original IRQ vector

;install 2-MHz during border speed-up
Install:
	sei
	lda iIRQ
	ldx iIRQ+1
	sta oIRQ        ;save original IRQ vector
	stx oIRQ+1
	lda #<doIRQ2M    ;set bottom-of-screen (phase 2)
	ldx #>doIRQ2M    
	sta iIRQ        ;as new IRQ vector
	stx iIRQ+1
	lda #0		;bank 15
	sta $ff00
	lda $d011
	and #$7f	;high raster bit = 0
	sta $d011
	lda #fastRaster	;low raster bits (251)
	sta $d012
	cli
	rts

;restore default IRQ 	
Remove:
	sei
	lda oIRQ
	ldx oIRQ+1
	sta iIRQ        ;restore original IRQ vector
	stx iIRQ+1
	lda #0		;bank 15
	sta $ff00
	lda $d011
	and #$7f	;high raster bit = 0
	sta $d011
	lda #$ff	;low raster bits = 255 (standard raster for IRQ)
	sta $d012
	cli
	rts

;phase 2 of 2MHz speed-up = change CPU to 2MHz
;and set raster IRQ for top-of-screen less 1 raster
;and do normal KERNAL routines of IRQ
;NOTE the CPU is in BANK 15 (the VIC is starting bottom border)
doIRQ2M:
	lda #1
	sta $d030	;CPU = 2MHz
	sta $d019	;clear VIC raster IRQ
	lda #<doIRQ1M    ;set top-of-screen (phase 1)
	ldx #>doIRQ1M
	sta iIRQ        ;as new IRQ vector
	stx iIRQ+1
	lda $d011
	and #$7f	;high raster bit = 0
	sta $d011
	lda #48+3-1	;low raster bits (default + Y_Scroll - 1 early raster = 50)
	sta $d012
	cli		;allow sprite/pen IRQs
	jsr $c22c	;flash VIC cursor, etc.
	jmp $fa6b	;update Jiffy Clock, control Cassette, handle SOUND/PLAY/MOVSPR
				;and return from IRQ


;phase 1 of 2MHz speed-up = change CPU back to 1MHz
;and set raster IRQ for bottom-of-screen
;NOTE the CPU is in BANK 15 (the VIC will soon start top of visible screen)
doIRQ1M:
	lda #<doIRQ2M    ;set bottom-of-screen (phase 2)
	ldx #>doIRQ2M
	sta iIRQ        ;as new IRQ vector
	stx iIRQ+1
	lda $d011
	and #$7f	;high raster bit = 0
	sta $d011
	lda #fastRaster	;low raster bits (251)
	sta $d012
	lda #1
	sta $d019	;clear VIC raster IRQ
	lsr		; A = 0
	sta $d030	;CPU = 1MHz
	jmp $ff33	;return from IRQ
	


EDIT / NOTE: The code switches between two IRQ routines; notice that "phase 2" will immediately change CPU to 2MHz speed (as soon as possible), while "phase 1" waits until the end before it sets CPU to 1MHz speed... thus, maximum performance from your 8502 :)

That code works well for "standard" VIC display (GRAPHIC 0, GRAPHIC 1, GRAPHIC 3), but it fails with split-screen modes (like GRAPHIC 2 or GRAPHIC 4).  The code can be fixed to work with those modes, but would be more complex.  The important thing is that it speeds up normal VIC (40-column) speed by about 22% (in detail, 18.3% for NTSC or 25.6% for PAL).

If you don't (can't ?) compile the Assembly Language code above, you can also download a small "PRG" file that you should BLOAD and then "install" with SYS 5888.

All by itself, the program will enhance many 40-column programs.  However, I hope the actual SOURCE CODE will explain how to implement a raster interrupt (or in this case, two interrupts).  BE AWARE, because of the simplicity of this sample, some 40-column programs (mainly, those which use split-screen) will FAIL.  Split-screen mode is possible with the "2MHz-Border" trick, but it requires a more sophisticated "wedge".


  NOTES!  

Please be aware the above assembly code is VERY primitive... it does not work with split-screen modes, nor with other (non-Raster) interrupts of VIC-II(e). In particular, BASIC 7 allows both SPRITE and PEN interrupts, but neither work with the simple/lame code posted above... you have been warned!!
©H2Obsession 1988, 1992, 2003, 2005, 2009, 2010, 2011, 2013, 2014, 2015
Test Program ©Bendevil, 2015 (used by permission)
Comments