
Show HN: 1.5kb Microkernel for Ben Eater's 6502 Computer - jroesner
https://github.com/janroesner/sixty5o2
======
Diederich
I'm actually more excited to see a new Ben Eater video on youtube than
anything else.

His stuff is just fantastic. Even though it's lower level than I've ever
worked, it's extremely entertaining and educational.

His 6502 series is just great, but I want to highlight another couple of
videos he did:

"Let's build a circuit that displays an image on a VGA monitor! In this video,
I talk about how VGA signals work and build a circuit that provides the
correct timing of sync signals so that a monitor recognizes the signal."

[https://www.youtube.com/watch?v=l7rce6IQDWs](https://www.youtube.com/watch?v=l7rce6IQDWs)

~~~
ravedave5
His video series was very enlightening. Seeing absolute lowest level how that
stuff is done is a wonderful insight into why stuff is the way it is today.

------
kazinator
Skimming through this, this is the first piece of code that my eyes drilled
into more deeply:

    
    
      LCD__clear_video_ram:
        pha                                         ; preserve A via stack
        tya                                         ; same for Y
        pha
        ldy #$20                                    ; set index to 32
      .loop:
        lda #$20                                    ; set character to 'space'
        sta VIDEO_RAM,Y                             ; clean video ram
        dey                                         ; decrease index
        bne .loop                                   ; are we   done? no, repea
        sta VIDEO_RAM                               ; yes, write zero'th location manually
        pla                                         ; restore Y
        tay
        pla                                         ; restore A
        rts
    

Surely we don't need to keep loading the space character into A on every
iteration?

Since Y starts at a hard-coded value that is (well) below $80, this could use
"bpl .loop" and drop the "sta VIDEO_RAM" special case.

In .select_option, I'd looking into doing a jump table. Ideas here:
[https://wiki.nesdev.com/w/index.php/Jump_table](https://wiki.nesdev.com/w/index.php/Jump_table)

~~~
jroesner
You are more than right. This is just my first assembly project in 20 years,
put together from scratch in a couple of days. Therefor I am more than
greatful for every constructive hint, that helps me improve. Thanks!

~~~
Someone
You probably know, but it also would help readability and portability if you
created separate constants _SPACE_ and _SCREENSIZE_ (or similar)

Also, if you want to go for idiomatic 6502 code, rather than readability:

\- you want to optimize for size and speed by looping down from C to zero
(rather than looping up from zero to C) where possible (because you don’t need
to do a _CMP_ to compare with zero)

\- _LCD__print_ wastes memory and CPU cycles. It can fall-through to
_LCD__print_with_offset_ , and that _could_ fall-through to _LCD_render_ ,

------
magicalhippo
Semi-related, I've been enjoying Robert Baruch's videos[1] on creating a FPGA
implementation of the 6800, using nMigen and formal verification. First videos
are almost like live coding, then he skips to a more compact format.

As a regular programmer, it's quite interesting to get into how the bits
actually end up getting the work done.

[1]:
[https://www.youtube.com/watch?v=85ZCTuekjGA&list=PLEeZWGE3Pw...](https://www.youtube.com/watch?v=85ZCTuekjGA&list=PLEeZWGE3PwbbjxV7_XnPSR7ouLR2zjktw)

------
Teknoman117
Watching Ben Eater's videos renewed my interest in making some simple
computers out of old hardware, mainly because the older hardware is simple
enough that you can work with it on a breadboard.

The interest eventually morphed into doing something with all of the old parts
I've hoarded. Going through the bins of parts, I've found things like 8051
microcontrollers (P80C550) and UARTs (AM85C30) and some old RTC units
(MC146818). I ended up picking up a few 68010's (among other things) off of
eBay with the hope of building a breadboard Linux computer, as slow as that
may be. I believe the 68010 may be the _only_ CPU in a DIP package still
supported in some capacity by Linux (as long as you provide an MMU).

Hopefully this will actually get me back into writing/making videos about my
projects.

------
that_jojo
I love, love, love Ben's videos, and this is an awesome project.

But to be as painfully pedantic as possible: can we please use the word
'monitor', here? Calling it a 'microkernel' really gives one the wrong initial
impression.

Still, very neat. Now write a BASIC!

~~~
kbrackbill
What does "monitor" mean in this context? Makes me think of either a display
or
[https://en.wikipedia.org/wiki/Monitor_(synchronization)](https://en.wikipedia.org/wiki/Monitor_\(synchronization\))
.

~~~
stevesimmons
I learnt assembly language programming on a Vic20 in 1983, using this Vicmon
machine code monitor:

[http://commodore.software/downloads/download/211-application...](http://commodore.software/downloads/download/211-application-
manuals/12177-vicmon-machine-code-monitor-manual)

I like this explanation of "monitor", from
[https://www.atarimagazines.com/creative/v9n12/272_A_monitor_...](https://www.atarimagazines.com/creative/v9n12/272_A_monitor_program_for_Vic.php)

"The novice machine language programmer often does not have an assembler.
Without an assembler, the programmer must assemble the program by hand, and
then enter it by hand. Even a small program could require hundreds of POKEs
followed by hundreds of PEEKs to verify that everything has been entered
correctly.

A good monitor gets around these problems. It allows the programmer to examine
memory locations sequentially. As each location is examined, the operator has
the option of changing it or looking at the next one. A good monitor program
also allows the operator to list a range of memory all at once. A third
monitor feature allows the operator to move a range of memory to a new
location in the computer. A final feature in a good monitor is the ability to
execute and return from a machine language program."

------
nategri
Learning about multiple wonderful things at once here. This is pretty much
catnip for 6502 fans.

------
danaur
Are there any good resources for learning electronics for someone with a
strong programming background and understand digital logic? Ben Eater videos
assume knowledge of electronics and would like to know more

~~~
jroesner
I found “Digital Computer Electronics” by Malvino and Brown really helpful. It
starts from scratch. Was also a recommendation from Ben Eater, but you will
only find used copies, since the book is not in print no more.

~~~
fernly
Don Lancaster's TTL Cookbook and CMOS Cookbook would be good companions for
the Ben Eater series.

[https://www.amazon.com/gp/product/0672210355/ref=dbs_a_def_r...](https://www.amazon.com/gp/product/0672210355/ref=dbs_a_def_rwt_bibl_vppi_i0)

[https://www.amazon.com/gp/product/0750699434/ref=dbs_a_def_r...](https://www.amazon.com/gp/product/0750699434/ref=dbs_a_def_rwt_bibl_vppi_i1)

Actually both books are available from Lancaster's website as a free PDF:

[https://www.tinaja.com/ebksamp1.shtml](https://www.tinaja.com/ebksamp1.shtml)

------
miohtama
This reminds me of C64 tape loaders or "turboa" that need to load the program
to RAM.

[https://www.atarimagazines.com/compute/issue57/turbotape.htm...](https://www.atarimagazines.com/compute/issue57/turbotape.html)

Also let's not forget Bill Gates's 17 bytes loader

[https://hackaday.com/2017/03/24/doing-it-with-fewer-bytes-
th...](https://hackaday.com/2017/03/24/doing-it-with-fewer-bytes-than-bill-
gates/)

~~~
localhost
Anyone else remember the PET Rabbit [1]?

"Load, Save, Verify, Execute 8 K in 38 seconds versus PETs 2 Minute 45
seconds, plus more!"

There was a newer version that I had which was called the ROM Rabbit vs. this
version that you had to load and save each time.

[1]
[http://archive.6502.org/publications/pet_paper/pet_paper_v3_...](http://archive.6502.org/publications/pet_paper/pet_paper_v3_i8_i9_i10.pdf)

------
kevstev
Nice! my 6502 kit arrived today! And there is snow in the forecast this
weekend- Really looking forward to building this.

~~~
edoceo
Post pics, if you make a bending unit[0]

[0]
[https://futurama.fandom.com/wiki/Bender_Bending_Rodríguez](https://futurama.fandom.com/wiki/Bender_Bending_Rodríguez)

------
jcmeyrignac
I just read your source code a bit, and there are a lot of things wrong.
First, you should ALWAYS clear the carry when using ADC or set the carry when
using SBC

For example: .increase: adc #1 sta POSITION_MENU

I have no idea if you increment or add two, since the carry is not cleared.

    
    
        clc
         lda CURRENT_RAM_ADDRESS_L
        adc #$01
        sta CURRENT_RAM_ADDRESS_L
        lda CURRENT_RAM_ADDRESS_H
        adc #$00
        sta CURRENT_RAM_ADDRESS_H
    

this is done by the usual INC CURRENT_RAM_ADDRESS_L BNE *+2 INC
CURRENT_RAM_ADDRESS_H

    
    
        ldy POSITION_CURSOR
        cpy #0  

cpy #0 is useless.

lda POSITION_CURSOR cmp #0 cmp #0 is useless

jsr / rts can be replaced by jmp

clear_ram is super slow

~~~
transitorykris
There's a kinder way to share this. Ben's teaching a number of things here
(basic electronics, computer architecture, assembly..) in an incredibly
inviting and rewarding way. I'm confident he's reaching people at varying
skill levels. Let's keep that energy going.

------
atum47
great job.

