Shop OBEX P1 Docs P2 Docs Learn Events
Problem with calling other objects — Parallax Forums

Problem with calling other objects

Rudy.WRudy.W Posts: 10
edited 2007-10-25 06:50 in Propeller 1
· Being pretty new on the Propeller I have written a main program calling an method·called "screen"·
· in· another object called "domotic screen"
· "Screen" consists of several text strings which have to be displayed
· To do so I included another object in "screen" called "Print_string_char"
··This won't work. It works ok when I put the "print_string_char) as a PUB in the screen object.

· I can't figure out what·I ·am I doing wrong.

·Please help

· Here is the code:

· {Maincode:}


Obj
···· ·Domotic_Screen·· :"Domotic_Screen"

CON
··· ·_clkmode = xtal1 + pll16x
···· _xinfreq = 5_000_000
VAR
· long· bitmap_base
· long· bitmap_longs

·
PUB start
· Domotic_Screen.start
· Domotic_Screen.screen


"' "Domotic_Screen".spin

CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· cols = 64
· rows = 48
· tiles = cols * rows
· spacetile = $8000 + $20 << 6
· bitmap_base = $4000
· display_base = $6000
· w_x = 40
· w_y = 30
· w_left = w_x * 16
· w_right = w_left + 256
· w_top = (48 - w_y) * 16
· w_bottom = w_top - 128

OBJ
· vga······ : "VGA_1024x768_Tile_Driver_With_Cursor"
·· pr······· : "Print_string_char"
·
VAR
· long· col, row, color, width, height
· long· boxcolor, boxptr
· long· array[noparse][[/noparse]tiles/2]
· long· cursor[noparse][[/noparse]1+32]
· long· cursor_x, cursor_y, cursor_col, cursor_def
···
PUB start | i, j, k

· vga.start(16, @array, @vgacolors, @cursor_x, 0, 0)··· ' Up to here it seems to work
·
PUB screen···························································· ' This does not anymore
· ·pr.printchar($100)················································ ' Pr refers to Obj Print_string_char
·· row := 0
·· col := 13
·· color :=4
·· pr.printtext(string(" This is a test string"))

DAT
·
· propeller long
· long %00000000_00000000_00000000_00000000
· long %01111110_00000000_00000011_11111000
· long %11111111_11110001_10111111_11111110
· long %11111111_11111111_11111111_11111111
· long %01111111_11111101_10001111_11111111
· long %00011111_11000001_10000000_01111110
· long %00000000_00000011_11000000_00000000
· long %00000000_00000011_11000000_00000000
· long %00000000_00000001_10000000_00000000
· long %00000000_00001111_11110000_00000000
· long %00000000_01111001_10011110_00000000
· long %00000001_11110011_11001111_10000000
· long %00000011_11100011_11000111_11000000
· long %00000111_11000111_11100011_11100000
· long %00001111_10000111_11100001_11110000
· long %00011111_10000111_11100001_11111000
· long %00011111_00000111_11100000_11111000
· long %00111111_00001111_11110000_11111100
· long %00111110_00001111_11110000_01111100
· long %00111110_00001111_11110000_01111100
· long %01111110_00001111_11110000_01111110
· long %01111100_00001111_11110000_00111110
· long %01111100_00011111_11111000_00111110
· long %01111111_11111111_11111111_11111110
· long %01111111_11110000_00001111_11111110
· long %01111000_00000000_00000000_00011110
· long %01100000_00000000_00000000_00000110
· long %00111100_00000000_00000000_00111100
· long %00001111_11110000_00001111_11110000
· long %00000011_11111111_11111111_11000000
· long %00000000_00011111_11111000_00000000
· long %00000000_00000000_00000000_00000000
· byte 15,15
·
· vgacolors long
· long $3C043C04······ 'lt grey on dk grey
· long $3C3C0404
· long $C000C000······ 'red
· long $C0C00000
· long $30003000······ 'green
· long $30300000
· long $0C000C00······ 'blue
· long $0C0C0000
· long $FC00FC00······ 'white
· long $FCFC0000
· long $FF80FF80······ 'red/white
· long $FFFF8080
· long $FF20FF20······ 'green/white
· long $FFFF2020
· long $FF28FF28······ 'cyan/white
· long $FFFF2828
· long $C0408080······ 'redbox
· long $3010F020······ 'greenbox
· long $3C142828······ 'cyanbox
· long $FC54A8A8······ 'greybox
· long $3C14FF28······ 'cyanbox+underscore
· long $F030C050······ 'graphics colors

··{ Print_string_char.spin}
OBJ
· vga············ :"VGA_1024x768_Tile_Driver_With_Cursor"
·
CON···················
· cols = 64
· rows = 48
· tiles = cols * rows
· spacetile = $8000 + $20 << 6
· bitmap_base = $4000
· display_base = $6000
· w_x = 40
· w_y = 30
· w_left = w_x * 16
· w_right = w_left + 256
· w_top = (48 - w_y) * 16
· w_bottom = w_top - 128
·
VAR

· long· col, row, color, width, height
· long· array[noparse][[/noparse]tiles/2]·
· long· boxcolor, boxptr
· long· cursor[noparse][[/noparse]1+32]
· long· cursor_x, cursor_y, cursor_col, cursor_defPri
···
PUB printchar(c) | i, k

· case c
··· $0D:··············· 'return?
····· newline
··· $20..$FF:·········· 'character?
····· k := color << 1 + c & 1
····· i := $8000 + (c & $FE) << 6 + k
····· array.word[noparse][[/noparse]row * cols + col] := i
····· array.word[noparse][[/noparse](row + 1) * cols + col] := i | $40
····· if ++col == cols
······· newline
··· $100:·············· 'clear screen?
····· wordfill(@array, spacetile, tiles)
····· col := row := 0
··· $101:·············· 'home?
····· col := row := 0
··· $108:·············· 'backspace?
····· if col
······· col--
··· $110..$11F:········ 'select color?
····· color := c & $F
PUB newline | i
· col := 0
· if (row += 2) == rows
··· row -= 2
··· 'scroll lines
··· repeat i from 0 to rows-3
····· wordmove(@array.word[noparse][[/noparse]i*cols], @array.word[noparse][[/noparse](i+2)*cols], cols)
··· 'clear new line
··· wordfill(@array.word[noparse][[/noparse](rows-2)*cols], spacetile, cols<<1)
···
PUB printtext(ptr)
·· repeat while byte[noparse][[/noparse]ptr]
··· printchar(byte[noparse][[/noparse]ptr++])·······

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-23 14:14
    The problem is that the VGA_1024x768_Tile_Driver_With_Cursor object referenced in print_string_char and in Domotic_screen are different. One solution would be to take out the OBJ vga in Domotic_screen and declare a PUB method in print_string_char called vga_start that just calls vga.start with the same parameters. That will solve the problem for now, but the whole issue of multiple references to objects from different other objects is messy. Sometimes you need for things to work the way they do now and sometimes you want a reference to an object to be the same object that's used elsewhere.

    The way to do the "shared objects" is to change the declarations of the variables from the VAR section to a DAT section since VAR storage is "per instance" (it's duplicated for each instance of the object) while DAT storage is allocated once for all instances of the object.
  • Rudy.WRudy.W Posts: 10
    edited 2007-10-25 06:50
    Thank you Mike for your very quick answer. I have been struggling with this problem but no success for the time being.
    The idea is to have a short main program from where i call several other objects including a print routine to display results.
    This is as I have understood so far the strong point of object oriented languages.

    I will continue with calling all objects from main and use declarations to DAT storage . Let's see what happens>

    Rudy Wempe from Holland.
Sign In or Register to comment.