Rewriting Kernal Routines

Basic and Machine Language

Moderator: Moderators

Post Reply
Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

Rewriting Kernal Routines

Post by Robbie »

I'm looking at CHROUT and thinking that I don't need a load of its functionality.
I'm wondering whether to copy the relevant parts of it inline into my main program loop.

It'll be a real pain, but will likely save a heck of a lot of cycles on execution. It'll also be a decent learning experience I reckon.

Your opinion: Worth it, or leave well alone?
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Rewriting Kernal Routines

Post by chysn »

If you have the RAM for it, only good can come from it, as a learning experience.

I'd just offer two bits of advice:

(1) Instead of re-implementing it as inline code, use a subroutine, and
(2) Try using the CHROUT vector at $0326 along with $FFD2 as your call address

I've never fully-re-implemented CHROUT, but I've made a couple CHROUT wedges (code that directs the $0326 vector, then sends control back to wherever the original hardware CHROUT is) that did things like allow multi-color characters via CHROUT (using some of the unused PETSCII characters as control characters), and another one that redirects output to a specific memory area (like a sort of virtual printer).

It can be fun and enlightening.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Rewriting Kernal Routines

Post by srowe »

The KERNAL routines are quite inefficient as they have to check the destination for every byte. If you always want output to the screen then you can always just call directly to the right subroutine. Depends what functionality you deem unnecessary.
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: Rewriting Kernal Routines

Post by Noizer »

Robbie wrote: Sun Oct 18, 2020 5:35 am I'm looking at CHROUT and thinking that I don't need a load of its functionality.
(...)
Your opinion: Worth it, or leave well alone?
Write your own chrout replacement from scratch with only the features you really need. You know what you want to achieve, the code has to simple reflect that.
Otherwise use CHROUT as is. It's like using the wheel already discovered. Not a shame 😌
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

Re: Rewriting Kernal Routines

Post by Robbie »

Noizer wrote: Sat Oct 24, 2020 10:12 am Write your own chrout replacement from scratch with only the features you really need. You know what you want to achieve, the code has to simple reflect that.
I've had a good poke around the internal organs of CHROUT and concluded exactly what you said: better just to write my own from scratch.

I've learnt quite a bit from seeing how CHROUT is coded, and it's reassured me that I'm doing things in the right way. It also reminded me just how repetitive it can be writing M/L (whole big chunks of load this, compare to that, branch, change something, repeat...)
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Rewriting Kernal Routines

Post by Mike »

Robbie wrote:I'm looking at CHROUT and thinking that I don't need a load of its functionality. [...]
When it comes to screen output, CHROUT not only needs to put the character on screen (after conversion of PETSCII to screencodes), it also accounts for the colour RAM update, and handling of some data structures that oversee the linking of physical screen lines into one logical line.

Add to this the single character API, and you see why CHROUT is so slow. If you just want to put characters on screen, at a fixed position, you're better off with a simple memory copy. For more complex uses (including scrolling), TNT once implemented an own CHROUT routine, which also handles screen sizes different from 22x23 characters: (-> Printing to screen without KERNAL).

As for another example - for MINIPAINT I implemented routines that put a 4x8 font into a bitmap, they're used there for the dialog boxes (help pages, file name requester, disk directory display). With the 160x192 pixels of the MINIGRAFIK screen, that gives one a soft 40-column "text" screen with 24 lines. The routines always draw an entire text line, and while doing so are twice as fast per character as KERNAL CHROUT on the normal text screen ... (that should tell you something :mrgreen:) ... and the accompanying scrolling routine is capable of scrolling 30 lines per second! I used these routines also elsewhere, and they're available as library. DarwinNE made good use of the routines in his adventure games. :)
Post Reply