terça-feira, 17 de dezembro de 2013

Hackaday Fubarino Contest

Este post está em inglês porque é minha entrada para o concurso da placa Fubarino no Hackaday.


Intro

My entry for the Fubarino Contest is a modified version of the Video Display Adapter developed by Daryl Rictor for his 6502 SBCs. 
The hack consists of adding an extra configuration jumper and a few lines of assembly to allow the selection of a Boot Logo with the Hack-A-Day URL, as needed for the contest.


Hardware

The modification on the original hardware consists of a 10k resistor connected at pin 26 of the AVR. The other side of the resistor goes to a pin header and then to the GND. This pin of the microcontroller (PC3) is normally configured as an ouput, but it is briefly set as an input during the startup. If the jumper J5 is present, a reading on the pin C3 will return "0". Otherwise it will return "1" (High). That's exactly the same technic used by the author of the project to detect (and thus select) the NTSC/PAL option.

The modded circuit can be seen on the picture below.




The circuit was assembled on standard board very similar to a veroboard. The Picture below shows the jumpers and the headers of the board.



Software

The original code underwent two modifications. One was the the boot logo itself. Instead of the original, I have reused the ASCII art from the retro.hackaday.com and added some stuff related to the contest.

/--------------------------------------\
|                                      |
|        __ __         __              |
|       / // /__ _____/ /__  ___ _     |
|      / _  / _ `/ __/  '_/ / _ `/     |
|     /_//_/\_,_/\__/_/\_\  \_,_/      |
|            ___                       |
|           / _ \___ ___ __            |
|          / // / _ `/ // /            |
|         /____/\_,_/\_, /             |
|                   /___/              |
|                                      |
|      Fubarino Contest entry by:      |
|                                      |
|          Daniel Jose Viana           |
|                                      |
|                  _                   |
|               ](o o)[                |
|                \|||/                 |
|                /   \                 |
|               ]     [                |
|                                      |
|         http://hackaday.com          |
|                                      |
\--------------------------------------/

For converting the raw ASCII logo into a file that could be read by the AVR assembler, I've created a Python script. The code of the script is presented below. It doesn't check if the raw log has more than 40 characters x 25 lines  but I think I can handle it by myself, so i kept the script simplest as possible.

# Script to convert ASCII characters
# into includable hexadecimal bytes 

# input and output files
fi = open('banner_raw.txt', 'r')
fo = open('h_banner.inc','w')

# write ASCII image preceeded with remarks  
for line in fi:
    fo.write('; ');
    fo.write (line)

# write entry point info
fo.write ('\n.CSEG')
fo.write ('\n.ORG 0x600')
fo.write ('\n')


# convert each line into hexadecimal values. conversion from
# http://code.activestate.com/recipes/496969-convert-string-to-hex/
fi.seek(0)
for line in fi:
    position=0
    for ch in line:
        #convert character to hexa
        hv = hex(ord(ch)).replace('0x', '')
        if len(hv) == 1:
            hv = '0'+hv
        hv=' $'+hv

        #place character into output file
        if position==0:
            fo.write('\n.db');
        if position < 40:
            fo.write (hv)
            if position !=39:
                fo.write (',')
        position=position+1
        
fo.write('\n')

fi.close()
fo.close()

The other modification on the original code was on the routine that shows the logo at the start-up. It was preceded by an almost copy-and-paste of the code that checks the NTSC/PAL. It changes the state of the PC3 line (port C, bit 3) and activates its pull-up. Then, After a little delay (a bunch of NOPs, indeed) the pin is read. If the jumper J5 is connected the 10k resistor will bring the line down. and the screen buffer will be initialized with the contest Logo. Otherwise the Clear Screen (FormFeed) routine is called and the program continues.

;******************************************************************************
; Initialize the Display SRAM
;******************************************************************************

; Check pin for easter egg. If low on startup, shows banner
 SBI portc, vd7 ; add pullup to pin C3 (vd7)
 ldi J, 0x17  ; set pin C3 as input
 out ddrc, J  ;
 nop   ; delay (wait for ext pull down
 nop   ;        resistor...)
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 nop   ; ""
 sbis pinc, vd7 ; is Pin c3 low?
 rjm SHOWBANNER ; Yes, Show Boot Banner
 rcall formfeed ; No, Simply clear the screen
 ldi Cursclk, 0xf8 ; init cursor blink timer 
 rjmp Restore_c3  ; continue 

showbanner:
; fill display SRAM with the Startup Banner 
 ldi ZL, 0x00
 ldi ZH, 0x0C ; set to start of Banner in Prog Mem
 ldi YL, 0x60
 ldi YH, 0x00 ; set to start of SRAM
 ldi XL, 0xE8
 ldi XH, 0x03 ; set X to 1000
 ldi J, 0x20  ;
frloop:
 lpm J, Z+  ; get boot image
 st  Y+, J  ; save to SRAM
 sbiw XL, 1  ; dec X
 brne frloop  ; do until X=0

 ldi Cursclk, 0x00 ; init cursor blink timer. 
    ; wait 256 blink times before initial CLS

RESTORE_C3:
 ldi J, 0x1F  ; set Pin C3 to output
 out ddrc, J  ;
 SBI portc, ackdpin ; raise Pin C3 to hi level

Notice the variable "Cursclk", which is responsible for the delay time of the banner. The main code waits for "Cursclk" counts reach 255 (0xFF) before entering in the normal operation state of the interface. This variable increments at each video frame and it is initialized 0 when the Boot Logo is selected, thus providing a delay of 256 video frames (close to 4 seconds ). On the other hand, when the Boot Logo is not selected, this variable is initialized with 248 (0xf8), wich corresponds 8 frames or something close to 130ms.

Video

The video below demonstrates the operation of the hack. Initially the board boots without the logo option. Then the logo jumper is inserted and the board is restarted, showing the logo.


Conclusion

Thanks for Daryl Rictor for sharing the code of his amazing interface. Without it this hack would not be possible.

And I hope you have enjoyed my hack!

Links:

Source Code Package:  VIDEO_DISPLAY.ZIP
Daryl Rictor's Video Terminal Page:
Hackaday Fubarino Contest:

/--------------------------------------\
|                                      |
|        __ __         __              |
|       / // /__ _____/ /__  ___ _     |
|      / _  / _ `/ __/  '_/ / _ `/     |
|     /_//_/\_,_/\__/_/\_\  \_,_/      |
|            ___                       |
|           / _ \___ ___ __            |
|          / // / _ `/ // /            |
|         /____/\_,_/\_, /             |
|                   /___/              |
|                                      |
|      Fubarino Contest entry by:      |
|                                      |
|          Daniel Jose Viana           |
|                                      |
|                  _                   |
|               ](o o)[                |
|                \|||/                 |
|                /   \                 |
|               ]     [                |
|                                      |
|         http://hackaday.com          |
|                                      |
\--------------------------------------/



Nenhum comentário: