XGS PIC development with XGS Basic-getting started

xgs_pic_03Writing in XGS Basic is a task, but the results, when run on the XGS, can be satisfying.  However, the process is a bit cumbersome and the language is incomplete and the documentation was never finished. However, the source code is freely available, so there is a way to fix some of the issues. I am not, however, ready to tackle that just yet.

No, instead, I thought I would share my process for writing and then executing code from XGS Basic on the XGS.

First, you’ll need a good programmer’s editor and one that, preferably, understands BASIC.  I am using Notepad ++.

You will also need a micro SD card, which came with your board OR you can use the Serial port on your computer and the appropriate cable plugged into the board.  I do not have a physical Serial port on my desktop, so I have a USB to Serial cable. However, Windows 8 does not support the cable. I have to use the SD card method.

Next, you’ll need the XGS Basic package.  You can download from the XGamestation web site, but it is on the DVD you got with your board.  Unzip the 1_5 version to a location on your computer and fire up that editor.

Compiling your code and running it:

  1. Open up a CMD window, you will need this when you compile.
  2. Write your source in your favorite editor and save it to the XGS Basic directory where you unzipped the package. 
  3. Switch to the CMD window and type: basicVM <name of the source.BAS> and then hit ENTER. (Where <name of the source.BAS> is your program file.)
  4. Your source will compile, provided you have no errors. If there is an error, you will be told what and where it is. Fix it and compile again.
  5. A successful compile will result in a .bai file being created (And, if you use serial, the .bai file is downloaded and executed on the board.)
  6. If you use the SD card method, copy the .bai file to the SD card and name it AUTORUN.BAI.  Plug the card into the board and turn it on. Your code should execute automatically.

Notepad ++ will allow you to automate the compile part, but I like doing things the hard way. I remember the steps this way.

Getting to know the hardware:

xgs_gamepad1I am, by no means, an expert on this board. I am somewhat new to this board, but have a basic understanding (the manual for the board is superb) of the device and how to use it.  XGS Basic has a few rudimentary functions and statements that talk to the hardware.  The most useful, for games, will be the graphics, of course, and the gamepad. The gamepad uses an Atari 2600 like connector, but is internally compatible with the NES style gamepads.  They are small, but comfortable and somewhat cheap feeling.  Sound is also possible, but I’ll save that for another day.

My introductory exercise was just to interact with the gamepad and draw something on screen, kind of like a rudimentary Etch a Sketch.  Now, before I go on, I have to say that my code is crap. It is but an example of talking to the hardware and not some fine piece of art. That said, take a look at the code below:

// Set the target as bitmap (not tile)
option target = "bitmap"

// ------------------------------------------------------

def paddle_speed = 1

// Gamepad direction defines
def gp_right  = 0x01
def gp_left   = 0x02
def gp_down   = 0x04
def gp_up     = 0x08
def gp_start  = 0x10
def gp_select = 0x20
def gp_red    = 0x40
def gp_yellow = 0x80

// colors
def RED          = 5
def BLACK        = 0

// ------------------------------------------------------
// 
// ------------------------------------------------------
call clear(0)
call text(10, 5, "Draw!")


Start:
    // Check for player input
    buttons = gamepad(0)
    
    // if RED button pressed, clear the screen
    if (buttons & gp_red) then call clear(BLACK)
    
    // go up or down, depending on the button press
    if(buttons & gp_up) then
        player1_paddleX = player1_paddleX - paddle_speed
    else if(buttons & gp_down) then
        player1_paddleX = player1_paddleX + paddle_speed
    end if
    
    // go left or right, depending on the button press
    if(buttons & gp_left) then
        player1_paddleY = player1_paddleY - paddle_speed
    else if(buttons & gp_right) then
        player1_paddleY = player1_paddleY + paddle_speed
    end if
    
    // quit if Select is pressed
    if (buttons & gp_select) then goto NoMore
    
    // if Start is pressed, alternate the color
    if (buttons & gp_start) and pdColor = RED then
        pdColor = BLACK
        else
        pdColor = RED
    end if
    
    // if yellow button pressed, cycle the color
    if (buttons & gp_yellow) then
        pdColor = pdColor +1
        if pdColor > 16 then 
            pdColor = 0
        end if
    end if
    
    // let the system catch up before updating the screen
    waitforvsync
    
    // draw our dot
    plot (player1_paddleY, player1_paddleX, pdColor)
    
    // go back for more
    goto Start
NoMore:
// end

The things to note are:

  • gamepad( 0 )
  • plot(x,y,color)
  • waitforvsync
  • call clear( 0 )
  • call text( x, y, text)

Call CLEAR( 0 ) clears the screen to black and Call TEXT(x,y,text) will display a string at the x,y coordinates on the screen. Simple enough. Now, for the fun stuff.

gamepad( 0 ) refers to the ‘player one’ controller while gamepad( 1 ) refers to the ‘player 2’ controller.  For our purposes today, we only have a player one controller.

PLOT (x, y, color) puts a pixel of color at the x,y coordinates.

WaitForVSync halts execution until after vertical blanking occurs. This should be done before drawing to the screen.

Most of my demo code is made up of interpreting the gamepad, so lets talk about that.

In order to interpret which button the user has pressed, we must ‘AND’ the button press with the value of the button we want to check for, so…here’s the values we need:

// Gamepad direction defines

def gp_right  = 0x01

def gp_left   = 0x02

def gp_down   = 0x04

def gp_up     = 0x08

def gp_start  = 0x10

def gp_select = 0x20

def gp_red    = 0x40

def gp_yellow = 0x80

You can copy that table into your code, near the beginning and before you check the gamepad. The ‘def’ simply tells BASIC that you are DEFining some constant values. Now, remember, you have to ‘AND’ the gamepad return value with the button value, such as:

// Check for player input

    buttons = gamepad(0)

// quit if Select is pressed

    if (buttons & gp_select) then goto NoMore

Notice, we get the current state of the gamepad using the ‘gamepad( 0 )’ function.  It’s value goes into the variable ‘buttons’. Next, we check to see if the user has pressed the SELECT button and, if so, we goto the label ‘NoMore’ and continue execution from there.  Go back and look at the demo code above. Go on, I’ll wait.

Oh, back so soon?  Ok.  Now, if you notice, we check for the directions (up, down, left, right) and the select, start, red and yellow buttons.  Each one has a purpose: the directionals, of course, will change the direction we draw, start will alternate the color, select will end the demo, red will clear the screen to black and yellow will cycle the color (which, does not currently work because of the start button functionality. I’ll fix that in another post.)

See how easy it is to interpret the gamepad?  Next time, we will take a look at some of the graphics stuff and discuss the two modes available (bitmap and tile) in XGS Basic.

From patch cords and punch cards to GUI’s and Mice: how programming evolved

Software development has come a very long way since the early days of 1946 when Eniac was programmed via patch cords.  When more modern computers, such as Univac, hit the market, programming them was better, but still required skills that were just impossible to come by. The problem was so bad, that it nearly derailed the whole industry before it really got going.

IBM704That changed, though, in 1954 when John Backus of IBM developed the FORTRAN language.  Considered the first successful high level language, FORTRAN, short for FORmula TRANslator, was, initially, greeted with a bit of skepticism, but that was satiated with the optimizing compiler. There was a fear that the code it generated would not be as tight as the previously hand assembled code, so the optimizing compiler was developed to quell those fears.

The first FORTRAN was released in 1957, followed up the next year with FORTRAN II, which contained enhancements including the addition of procedural programming. Functions and subroutines allow the developer to create their own functions for the first time.

FORTRAN was a big step forward, but it had its limitations. Primarily, it was not very good with business uses. The solution would come from a committee that formed in 1959.  The committee was formed by people from the government and private industry.

FLOW-MATIC, a language developed by Grace Hopper, was used as the foundation for COBOL, or COmmon Business Oriented Language. FLOW-MATIC was drawn from more than other language specs mainly because it was the only one that had actually been deployed and used. COBOL gained wide acceptance in business and enjoyed a run that continues today, though it use has dramatically declined over the last couple of decades. 

Both FORTRAN and COBOL served both the science, research and business communities, but they were not all that easy to master. FORTRAN more than COBOL, but were still out of reach for many.  In 1962, John Kemeny and Thomas Kurtz developed the Beginners All-purpose Symbolic Instruction Code, or BASIC.  Panned by most ‘professional’ programmers and purists, BASIC, nonetheless, gained wide acceptance in the 1970’s with the advent of the microcomputer.

Initially, BASIC was both the operating system and language of many homebrew and early retail microcomputers. However, those machines were very limited in memory and power. The version of BASIC that was generally in use was called Tiny BASIC. These ‘tiny’ languages truly were tiny: most took only 2.5 to 4K of memory. They generally only handled integer numbers, limited or no string handling and only the ‘basic’ of statements (like IF-THEN, GOTO, PRINT, INPUT, etc.) were included. 

Things looked up, however, when the ALTAIR computer was introduced. Two kids decided they would supply a BASIC language for the computer. Paul Allen and Bill Gates set up shop in New Mexico and began Micro-Soft. Gates delivered the final bits of code the day they were supposed to meet with Ed Roberts, the owner of the MITS company, the producer of the Altair.  Micro-Soft Basic became the defacto ‘standard’ for microcomputer Basic for years to come. It was also one of the most pirated pieces of software.

Micro-soft, later changed to Microsoft, continually enhanced the language, adding low-res, monochrome graphics statements, then hi-res color, disk file handling and more. In 1991, the company introduced Visual Basic, a Windows based development environment. For the first time, Windows applications could be developed, quickly and without having to know ‘C’ or how the innards of Windows worked. It enabled companies, large and small, to embrace Windows without having spend lots of money developing or purchasing specialty applications. The company also continued to develop its DOS versions with the Professional Development System and a DOS version of Visual Basic called Visual Basic for DOS or VBDOS for short. I, personally, developed several applications with VBDOS and it was, by far, my favorite text based version other than NI/BL, a variation of Tiny Basic for the National Semiconductor SC/MP in the ‘70s.

Microsoft held VB in such high regard, that it became the built in scripting language of its Office Suite, a second scripting language in its browsers, and for Windows itself. VBScript, while it no longer is being developed by the company, is a highly versatile language and is under appreciated.

No discussion of programming languages would be complete without talking about C.

C was developed between 1969 and 1973 by Dennis Ritchie at Bell Labs. C is probably the most widely used language. It is used to develop everything from games to operating systems (such as Unix and Windows.) While it generally is considered a high level language, C more closely resembles cross between BASIC and Assembler. It requires knowledge of how the CPU works, things like pointers and other lower level objects than, say a BASIC or even COBOL.  It does, however, generate smaller and more efficient code.

C gained popularity in the 1980’s but it, too, had ‘Tiny’’ versions, but they did not catch on quite like Tiny Basic did. However, it did spawn a more powerful version called C++. C++ is an object oriented language that did catch on…like wildfire. C++ is a true modern language and was the inspiration for other modern languages like JAVA and C Sharp (C#).

Gone are the days of punch cards, magnetic tape and printouts. With our graphical development environments, mice, touch screens and languages like C Sharp, VB and web development technologies, programming has definitely come a long way. And, that shortage of programmers? Gone.

I must say, those days in the 1970’s and 80’s, and the underpowered computers, were a blast. For geeks like me, Tiny Basic was a godsend. I was able to learn something that, later, would provide a career. I got to experience, first hand, the birth of the modern computer era. I can remember, eagerly, getting a computer magazine and tediously entering BASIC code and then having to ‘fix’ it to work with my particular flavor of BASIC. But, I did. I got just about everything I entered to work. Yeah, I missed things like Prom and high school football, but I would not trade it for anything. I think the way I felt was pretty close to those early pioneers in the early ‘50s.  Amazing, that sums it up.

A slice of Pi, Raspberry Pi

DSC_4341Raspberry Pi. No, not the kind you eat and I didn’t forget the ‘e’ in Pi. Raspberry Pi is the moniker given to a tiny, very tiny, ARM based computer.  The computer designed, primarily, for the UK educational market.  Raspberry Pi Foundation is a UK non-profit seeking to make computing as cheap as can so they can excite young (and old) people and spur interest in computing, a noble and worthy cause.

The Lilliputian computers, which measure 85.60mm x 56mm x 21mm, start at a cost of $25(US). For $25, one gets a complete computer with an ARM11 processor, 256mb of RAM, a graphical processor capable of decoding high definition, 1080p, video. The board has composite video via an RCA style composite video jack as well as an HDMI port so you plug the board into your hi-def, ultra-tech flat panel or a decidedly low tech, standard def, CRT for old school computing.  For ten bucks more, you get twice the memory and an on-board ethernet port. No WiFi on either, but you can add a WiFi dongle using the included USB port.

I ordered the Model B, the $35 board. I also ordered a clear case and purchased a 16gb SD card for storage. I downloaded the “official” Raspi Linux distro and ‘burned’ the image to the SD card using a tool they recommended (Win32DiskImager)  There is a great guide for preparing your SD card here. However, downloading the image file (here), formatting your SD card (FAT32) and then using Win32DiskImage to burn the image to the SD card is pretty much all you need to do. The guide I mentioned above includes instructions for Mac users as well.

Since I already had a dozen USB chargers, I did not purchase one, however, they are under ten bucks and it never hurts to have one more, right?

rpi3Upon plugging in a composite monitor (a battery powered digital portable TV with composite input) and the power, I was ready to check out the computer.  For keyboard and mouse, I used a Logitech wireless keyboard with integrated touch pad that I purchased for my Asus tablet. 

To my amazement and pleasure, the computer bootedrpihdmivideo1 up in just a few seconds. After completing a short setup sequence, the Raspberry Pi booted into a nice windowed gui.  This particular distribution of Linux comes preloaded with several web browsers, two IDE’s and two Python interpreters as well as a few other assorted utilities and applications. (No games, save for a few that were used to demonstrate Python.)

Since the little TV I was using was just horrid as a monitor, I dug up an old Playstation One monitor (you know, the ones that you could get that screwed onto the PSOne white console.) This monitor is much nicer than the TV-which was not designed to be used as a computing display device. I also tried out the HDMI connection on our 32inch Westinghouse (remember, that’s the one that has to be ‘activated’…grrr!!) set. Needless to say, this is the way to go.

What you need:

Raspberry Pi $35
4gb (minimum) SD Card $10 (you might get it cheaper)
USB Charger (750~1.0 amp) $10 (I had one, so I did not buy one.)
Linux Distro (RasPi) $0 (add $12 if you buy one with the OS installed.
SD card image writer for your OS $0

Total for Model B

$55

The Pi, while not a speed demon, renders web pages with surprising ease and speed. It is not as fast as my Asus tablet or even my company issued iPhone 5, but it is usable and I would not get upset if it were my only means of getting on Facebook or posting to this blog.

I am quite pleased with my under $50 computer. It is a great and cheap way to introduce someone to computing or to tinker with or whatever. It is well documented and there are a ton of ideas already out in the ether. Things like cool little arcade cabinets running Mame or Nintendo emulators, dog food dispenser and Pandora radios. I’m going to use mine to expand my programming horizons and to go old school with Tiny Basic.  Learning to appreciate Linux might be in the works as well.

Resources:

EDIT: reposted photo of Facebook with names removed.

Retro-Computing: the TRS-80 Model 100 and old school coding

TRS-80 Model 100 Portable ComputerSometime in late 2010, I purchased a TRS-80 Model 100 Portable Computer. The computer, one of the first true notebook computers, was a marvel of its time: integrated keyboard and LCD screen, built in MODEM, up to 32K (yes, K…that’s THOUSANDS of bytes) of RAM and a host of software.  The computer ran off of AA batteries and was fully self contained. It had Microsoft Basic (THE standard of the day) along with personal information management software. It was a very popular computer and you can still see them in use today.

Recently, I dusted the computer off and took it for a spin.  I wanted to show my son just how a geek in my day had ‘fun’.  I sat there, while he played Call of Duty on the Xbox and wrote a crude space invader style game. Right there, on the device. NO development environment to speak of, just the line oriented editor.  Oh, and LINE NUMBERS.  Remember them?

100 Print”Hello, World”

Wow. I have not used line numbers in years…decades, even.  I don’t know, there’s something quaint about them…having to figure out a decent increment because, you know, you will, at some point, have to insert a line or two of code because you left something out or, more likely, figured out you needed to add or move something to fix something somewhere else.  Ah, the joys of spaghetti code.  Nothing like it.

So, in that hours time, I managed something that sorta kinda resembles a one invader space invaders game. My little invader, which was sorta animated, would go back and forth on the top line of the 7 line screen. My base was centered on the bottom of the screen and touching the space bar would ‘fire’ the missile at the invader.  Only a direct hit would score your ten points. The game continued until you press Q.  This version does not have the alien invader retaliating, only moving back and forth.  With only about thirty lines of code, there isn’t much there.  But, hey, not bad for such a crude little machine and hours worth of time. 

This little exercise reminded me that sometimes we don’t always need the most recent, hottest or best of anything to have a good time.  I was having a ball playing with the computer, figuring out how to do things without reading the manual (which I have.)  And, for this developer, using that old flavor of Microsoft Basic was a blast.  Line numbers, PRINT @, and the ever so enthralling ‘SOUND’, which makes high pitched beeps. Good stuff.  Makes me appreciate .Net even more.

If I can transcribe (I.E. feel like retyping) the code, I’ll post it here, if there is any interest.

One note about the computer: while the LCD screen is terrible, the rest of the computer, ergonomically, is superb.  The keyboard has a nice feel and the whole thing is surprisingly light.  The fact that it uses AA batteries is awesome. No cumbersome recharger, expensive batteries or funky adaptors. Just AA batts. Oh and the menu screen is easy to use, but, for some odd reason, you have to actually go into BASIC and issue a command to delete a file.  Weird.  Hey, it was the 1980’s. Hell, it’s easier to use than some newer devices today…like Pandigital’s e-Reader and the Kindle.

Update:

Here is a wonderful site full of TRS-80 information and nostalgia. Also, there is an emulator for the Model 100.  I won’t put a direct link here since the emulator contains copyrighted material, just use Bing or that other search engine.  Search for VirtualT.

Digg This