Jump to content
IGNORED

Coding


Willsy

Recommended Posts

At my real job - we're wrapping up something awesome (you'll see it soon!) and after that - hopefully - there will be somewhat of a reprieve. I've got a partially finished XB game (see my Avatar) that wasn't working out - but maybe it will under the compiler...

 

-H

Link to comment
Share on other sites

Instead of working on my 3 unfinished games, I ported this XB program CRISTAUX.zip from my father to VB.NET. I tried to make a reusable TI99 class. Only basic graphics are implemented, no sprites, no sound, no files. VB.NET library.zip

 

Here is the code. Sorry for the french names ;)

 


Public Class TI99
   Private couleurs(32) As Byte
   Private motifs(256 *  As Byte
   Private écran(32 * 24) As Byte
   Private couleur_fond As Couleur
   Private accueil As Boolean
   Private offset_caractères As Byte
   Protected sélection(32 * 24) As Boolean
   Private WithEvents timer1 As New Timer
   Private sélection_inversée As Boolean
   Public Event Clic(ByVal x As Integer, ByVal y As Integer)
   Public Event Touche(ByVal e As Windows.Forms.KeyEventArgs)
   Public Event Start()
   Private tâche As Threading.Thread
   Public semaphore As New Threading.Semaphore(0, 1)
   Private à_afficher As Boolean
   Private WithEvents timer2 As New Timer
   Private attendre As Boolean
   Protected vitesse As Integer
   Protected compteur_attentes_affichage As Integer
   Private nombre_attentes_affichage As Integer
   Protected lecture_sons As New Media.SoundPlayer
   Protected message_affiché As Boolean
   Private touche_pressée As Boolean

   Public Enum Couleur
       Transparent
       Noir
       VertMoyen
       VertClair
       BleuFoncé
       BleuClair
       RougeFoncé
       Cyan
       RougeMoyen
       RougeClair
       JauneFoncé
       JauneClair
       VertFoncé
       Magenta
       Gris
       Blanc
   End Enum

   Private valeurs_couleurs() As Color = { _
       Color.FromArgb(0, 0, 0), _
       Color.FromArgb(0, 0, 0), _
       Color.FromArgb(33, 206, 66), _
       Color.FromArgb(90, 222, 123), _
       Color.FromArgb(82, 82, 239), _
       Color.FromArgb(123, 115, 255), _
       Color.FromArgb(214, 82, 74), _
       Color.FromArgb(66, 239, 247), _
       Color.FromArgb(255, 82, 82), _
       Color.FromArgb(255, 123, 123), _
       Color.FromArgb(214, 198, 82), _
       Color.FromArgb(231, 206, 132), _
       Color.FromArgb(33, 181, 57), _
       Color.FromArgb(206, 90, 189), _
       Color.FromArgb(206, 206, 206), _
       Color.FromArgb(255, 255, 255) _
   }

   Private Sub TI99_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       accueil = True
       Initialiser()
       Afficher()
       ChangerVitesse(0)
       Beep()
   End Sub

   Private Function StringToByteList(ByVal s As String) As List(Of Byte)
       Dim b As New List(Of Byte)
       Dim c(2) As Char
       c(0) = vbCrLf
       c(1) = " "
       Dim ls() As String = s.Split(c, StringSplitOptions.RemoveEmptyEntries)
       For Each s2 As String In ls
           Try
               b.Add(Byte.Parse(s2, Globalization.NumberStyles.HexNumber))
           Catch ex As Exception
           End Try
       Next
       Return b
   End Function

   Public Sub CallClear()
       For i As Integer = 0 To 32 * 24 - 1
           écran(i) = 32 + offset_caractères
       Next
   End Sub

   Private Sub Initialiser()
       Dim b As New Bitmap(32 * 8, 24 * 
       pb_écran.Image = b
       couleurs = StringToByteList(My.Resources.couleurs_gpl).ToArray
       motifs = StringToByteList(My.Resources.patterns_gpl).ToArray
       CallScreen(Couleur.Cyan)
       CallClear()
       AfficherAccueil()
   End Sub

   Private Sub Afficher(ByVal x As Integer, ByVal y As Integer)
       Dim bmp As Bitmap = pb_écran.Image
       Dim c As Byte = écran(x + y * 32)
       Dim fci As Couleur = couleurs(c \  >> 4
       Dim bci As Couleur = couleurs(c \  And 15
       If fci = Couleur.Transparent Then
           fci = couleur_fond
       End If
       If bci = Couleur.Transparent Then
           bci = couleur_fond
       End If
       Dim fc As Color = valeurs_couleurs(fci)
       Dim bc As Color = valeurs_couleurs(bci)
       For i As Integer = 0 To 7
           For i2 As Integer = 0 To 7
               Dim b As Boolean = motifs(c * 8 + i) >> (7 - i2) And 1
               If sélection(x + y * 32) And sélection_inversée Then
                   b = Not b
               End If
               If b Then
                   bmp.SetPixel(x * 8 + i2, y * 8 + i, fc)
               Else
                   bmp.SetPixel(x * 8 + i2, y * 8 + i, bc)
               End If
           Next
       Next
   End Sub

   Public Sub Afficher()
       For x As Integer = 0 To 31
           For y As Integer = 0 To 23
               Afficher(x, y)
           Next
       Next
       pb_écran.Invalidate()
   End Sub

   Public Sub CallHChar(ByVal y As Integer, ByVal x As Integer, ByVal c As Byte, ByVal n As Integer)
       For i As Integer = 1 To n
           écran(x - 1 + (y - 1) * 32) = c + offset_caractères
           x = x + 1
           If x > 32 Then
               x = 1
               y = y + 1
           End If
       Next
       Invalider()
   End Sub

   Public Sub CallHChar(ByVal y As Integer, ByVal x As Integer, ByVal c As Byte)
       CallHChar(y, x, c, 1)
   End Sub

   Public Sub DisplayAt(ByVal y As Integer, ByVal x As Integer, ByVal s As String)
       Dim e As New System.Text.ASCIIEncoding
       Dim b(s.Length) As Byte
       e.GetBytes(s, 0, s.Length, b, 0)
       For i = 0 To s.Length - 1
           écran(x + 1 + (y - 1) * 32) = b(i) + offset_caractères
           x = x + 1
           If x > 28 Then
               x = 0
               y = y + 1
           End If
       Next
       Invalider()
   End Sub

   Private Sub BarreAccueil(ByVal y As Integer)
       Dim c As Byte = &H60
       For i As Integer = 0 To 15
           For i2 As Integer = 0 To 2
               écran((y + i2) * 32 + i * 2) = c
               écran((y + i2) * 32 + i * 2 + 1) = c
           Next
           c = c + 8
       Next
   End Sub

   Private Sub AfficherAccueil()
       BarreAccueil(0)
       For c As Byte = 1 To 3
           écran(5 * 32 + 14 + c) = c
       Next
       For c As Byte = 4 To 6
           écran(6 * 32 + 14 + c - 3) = c
       Next
       For c As Byte = 7 To 9
           écran(7 * 32 + 14 + c - 6) = c
       Next

       DisplayAt(10, 7, "TEXAS INSTRUMENTS")
       DisplayAt(12, 9, "HOME COMPUTER")
       DisplayAt(17, 1, "READY-PRESS ANY KEY TO BEGIN")
       BarreAccueil(18)
       écran(22 * 32 + 4) = &HA
       DisplayAt(23, 4, "1981  TEXAS INSTRUMENTS")
   End Sub

   Public Sub CallScreen(ByVal c As Couleur)
       BackColor = valeurs_couleurs(c)
       couleur_fond = c
       Invalider()
   End Sub

   Private Sub QuitterAccueil()
       Beep()
       accueil = False
       offset_caractères = &H60
       motifs = StringToByteList(My.Resources.patterns_basic).ToArray
       For i As Integer = 0 To 31
           couleurs(i) = &H10
       Next
       CallClear()
       timer1.Interval = 200
       timer1.Start()
       RaiseEvent Start()
   End Sub

   Private Function CaractèreClic(ByVal pt As Point) As Point
       pt.X = CSng(pt.X) * pb_écran.Image.Width / pb_écran.Width \ 8 + 1
       pt.Y = CSng(pt.Y) * pb_écran.Image.Height / pb_écran.Height \ 8 + 1
       Return pt
   End Function

   Private Sub TraiterClic(ByVal pt As Point)
       If accueil Then
           QuitterAccueil()
           RaiseEvent Start()
       Else
           pt = CaractèreClic(pt)
           RaiseEvent Clic(pt.X, pt.Y)
       End If
   End Sub

   Private Sub TI99_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
       If accueil Then
           TraiterClic(e.Location)
       End If
   End Sub

   Private Sub TI99_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
       If Not touche_pressée Then
           If accueil Then
               QuitterAccueil()
           Else
               RaiseEvent Touche(e)
               e.Handled = True
           End If
       End If
       touche_pressée = True
   End Sub

   Private Sub TI99_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
       touche_pressée = False
   End Sub

   Private Sub pb_écran_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb_écran.MouseClick
       TraiterClic(e.Location)
   End Sub

   Public Sub CallChar(ByVal c As Byte, ByVal s As String)
       c = c + &H60
       For i As Integer = 0 To 7
           motifs(c * 8 + i) = Byte.Parse(s.Substring(i * 2, 2), _
               Globalization.NumberStyles.HexNumber)
       Next
       Invalider()
   End Sub

   Public Sub Sélectionner(ByVal x As Integer, ByVal y As Integer)
       sélection(x - 1 + (y - 1) * 32) = True
   End Sub

   Public Sub Désélectionner(ByVal x As Integer, ByVal y As Integer)
       sélection(x - 1 + (y - 1) * 32) = False
   End Sub

   Public Function AucuneSélection() As Boolean
       For x As Integer = 0 To 31
           For y As Integer = 0 To 23
               If sélection(x + y * 32) Then
                   Return False
               End If
           Next
       Next
       Return True
   End Function

   Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
       sélection_inversée = Not sélection_inversée
       If Not AucuneSélection() Then
           Afficher()
       End If
   End Sub

   Public Sub CallGChar(ByVal y As Integer, ByVal x As Integer, ByRef c As Byte)
       c = écran(x - 1 + (y - 1) * 32) - offset_caractères
   End Sub

   Public Sub ToutDésélectionner()
       For i As Integer = 0 To 32 * 24 - 1
           sélection(i) = False
       Next
   End Sub

   Public Function Asc(ByVal s As String) As Byte
       Dim e As New System.Text.ASCIIEncoding
       Dim b(s.Length) As Byte
       e.GetBytes(s, 0, s.Length, b, 0)
       Return b(0)
   End Function

   Private Function Arrêté() As Boolean
       Return tâche Is Nothing OrElse Not tâche.IsAlive
   End Function

   Public Sub Démarrer()
       If Arrêté() Then
           timer2.Start()
           tâche = New Threading.Thread(AddressOf TâcheMain)
           tâche.Start()
       End If
   End Sub

   Private Sub TâcheMain()
       Try
           Main()
       Catch ex As Threading.ThreadAbortException
       End Try
   End Sub

   Public Overridable Sub Main()
   End Sub

   Public Sub Invalider()
       If Not Arrêté() Then
           à_afficher = True
           If (vitesse < 5 Or compteur_attentes_affichage > nombre_attentes_affichage) _
           And vitesse < 10 Or message_affiché Then
               attendre = True
               compteur_attentes_affichage = 0
               semaphore.WaitOne()
           Else
               If vitesse < 10 Then
                   compteur_attentes_affichage = compteur_attentes_affichage + 1
               End If
           End If
       End If
   End Sub

   Private Sub timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer2.Tick
       If à_afficher Then
           à_afficher = False
           Afficher()
           If attendre Then
               attendre = False
               semaphore.Release()
           End If
       End If
   End Sub

   Public Sub Arrêter()
       If Not Arrêté() Then
           tâche.Abort()
       End If
   End Sub

   Public Sub CallColor(ByVal i As Integer, ByVal fc As Integer, ByVal bc As Integer)
       couleurs(i + 15) = ((fc - 1) << 4) + bc - 1
       Invalider()
   End Sub

   Public Sub ChangerVitesse(ByVal v As Integer)
       vitesse = v
       If vitesse < 5 Then
           timer2.Interval = 250 / (vitesse + 1)
       Else
           timer2.Interval = 1
           nombre_attentes_affichage = (vitesse - 5) * 500 / 6 + 10
       End If
   End Sub

   Public Function ImageCaractère(ByVal c As Byte) As Image
       c = c + offset_caractères
       Dim bmp As New Bitmap(8, 
       Dim fci As Couleur = couleurs(c \  >> 4
       Dim bci As Couleur = couleurs(c \  And 15
       If fci = Couleur.Transparent Then
           fci = couleur_fond
       End If
       If bci = Couleur.Transparent Then
           bci = couleur_fond
       End If
       Dim fc As Color = valeurs_couleurs(fci)
       Dim bc As Color = valeurs_couleurs(bci)
       For i As Integer = 0 To 7
           For i2 As Integer = 0 To 7
               Dim b As Boolean = motifs(c * 8 + i) >> (7 - i2) And 1
               If b Then
                   bmp.SetPixel(i2, i, fc)
               Else
                   bmp.SetPixel(i2, i, bc)
               End If
           Next
       Next
       Dim bmp2 As New Bitmap(16, 16)
       Dim gc As Graphics = Graphics.FromImage(bmp2)
       gc.DrawImage(bmp, New Rectangle(0, 0, 16, 16))
       Return bmp2
   End Function

   Public Sub Beep()
       lecture_sons.Stream = My.Resources.Start
       lecture_sons.Play()
   End Sub
End Class

 

 

Here is the status of my 3 unfinished games:

 

NYOG'SOTHEP (GCC) NYOG_SOTHEP 2.zip

Free high memory (code): 5943

Free low memory (data+stack): ~1000

TODO:

- Computer player

- Menu to load/save a game

 

TI-WARS (TurboForth/FIG-Forth) TI-WARS 5.zip

Free high memory in TurboForth: 686 bytes

Free low memory in TurboForth: 8192 bytes

Free high memory in FIG-Forth: ~2000 bytes

Free low memory in FIG-Forth: I don't have the docs, I think it's not usable

TODO:

- Battle system

- Submarines

- Computer player

- Remove the map editor to free some memory if necessary

 

SOKOBAN (Assembly) SOKOBAN ASM.zip

TODO:

- Check when memory is full (levels + recorded moves).

- Allow the user to split the current file (levels + recorded moves) to continue the game when the memory is full

Edited by lucien2
Link to comment
Share on other sites

...

Free low memory in FIG-Forth: I don't have the docs, I think it's not usable

...

 

The only readily available low memory in TI Forth (the fig-Forth I presume you mean) is the 806-byte segment from 3CDAh-3FFFh, where the return stack resides. You could use some of the memory starting at the low end (3CDAh) because the return stack grows down from 3FFFh. Of course, you would need to experiment to see how much you could use before stepping on the return stack.

 

You could probably also co-opt space from the five TI Forth block buffers (2010h-3423h), this time from the high end, by modifying LIMIT$ . I haven't tried this, so I can't say what might happen if you do. I am not sure how LIMIT$ gets set by the system, so I cannot offer much advice without a little research. I would try reducing LIMIT$ by 1028 bytes to try it (1028 bytes is the size of each of the 5 block buffers).

 

There's more information in TI Forth Instruction Manual "1st Edition 2012" in the "TI-99/4A development resources" sticky thread at the top of this forum. I am in the process of producing a 2nd edition, but have been sidetracked by some TurboForth floating-point stuff I've been working on with @Willsy.

 

...lee

Link to comment
Share on other sites

I had the opportunity to play Carcassone this past weekend. It's been a long time since I played a board game - this was simple yet intriguing. The fixed elements would be easy to replicate on a computer though I'm not sure how gameplay would be achieved. It got me thinking there may be some simpler mechanics to be explored in the world of games ;)

 

http://en.wikipedia.org/wiki/Carcassonne_(board_game)

Link to comment
Share on other sites

Working on a small game to get my feet re-wetted before I dive back into one of my many overambitious unfinished projects. And hoping to test this new one out with the compiler!

 

All I have actually coded so far is a cute little CALL DICE subprogram to draw a 16x16 pixel dice anywhere on the screen. But the finished game should be pretty cool... it's a dice game my son and I devised at the dining room table with actual dice and paper. More info later.

 

TIDice.jpg

  • Like 1
Link to comment
Share on other sites

Does Forth support the SAMS?

That would be a great place to put screens and swap them out quickly.

 

TurboForth does.

 

You could also put screens in blocks in screen format and pre-load them. The blocks system in Forth works like a cache; if you pre-load them then they sit in ram, ready to be used. In turboforth the cache is in vdp memory so it occupies no program space at all.

Link to comment
Share on other sites

I had the opportunity to play Carcassone this past weekend. It's been a long time since I played a board game - this was simple yet intriguing. The fixed elements would be easy to replicate on a computer though I'm not sure how gameplay would be achieved. It got me thinking there may be some simpler mechanics to be explored in the world of games ;)

 

http://en.wikipedia....nne_(board_game)

Carcassone is the poster boy of modern social board games, extremely easy to learn, infinite replayability. However, implementing a computerized version on the TI would be quite a challenge given the number of tiles involved unless the SAMS card is used. The game mechanics per se should be feasible as they are pretty straightforward. I say go for it :D

Link to comment
Share on other sites

Carcassone is the poster boy of modern social board games, extremely easy to learn, infinite replayability. However, implementing a computerized version on the TI would be quite a challenge given the number of tiles involved unless the SAMS card is used. The game mechanics per se should be feasible as they are pretty straightforward. I say go for it :D

 

It's become a family favorite. The expansion packs are great too. It's available on the xbox, so not sure why it wouldn't work on the TI. Might be a challenge to get everything into 2x2 squares and fit the board on the screen - scrolling would be required and keeping all that in your head when you look at things to do would probably be the biggest challenges. But, for scoring and the like, it would be great.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...