|
Joined: Oct 2014
Posts: 4
Member
|
Member
Joined: Oct 2014
Posts: 4 |
Reading this makes me realize how much a dot-matrix printer is like a write-only floppy drive, except it controls the exact media position instead of waiting for it to come around to the right spot. Great idea for a hackerspace project: a dot-matrix printer that spins the paper and waits for the right spot to come around for each dot.
|
|
|
|
Joined: May 2009
Posts: 2,222 Likes: 387
Very Senior Member
|
Very Senior Member
Joined: May 2009
Posts: 2,222 Likes: 387 |
True, but you would need to ensure that your paper has an index hole.
|
|
|
|
Joined: Mar 2001
Posts: 17,234 Likes: 259
Very Senior Member
|
Very Senior Member
Joined: Mar 2001
Posts: 17,234 Likes: 259 |
Or write some kind of a sync mark and watch for it to come around.
|
|
|
|
Joined: Feb 2014
Posts: 1,124 Likes: 193
Very Senior Member
|
OP
Very Senior Member
Joined: Feb 2014
Posts: 1,124 Likes: 193 |
I liked being able to call lua so much I made a class called luacall: /***************************************************************************
luacall.h
Utility class for calling lua
***************************************************************************/
#ifndef MAME_LUACALL_H
#define MAME_LUACALL_H
#pragma once
class lua_engine;
class luacall {
public:
static lua_engine *m_luaengine;
static void (lua_engine::* lualoadstringf) (const char * astr);
static int (lua_engine::* luagetintvarf) (const char * astr);
static double (lua_engine::* luagetdoublevarf)(const char * astr);
static std::string (lua_engine::* luagetstringvarf)(const char * astr);
static void lualoadstring(const char *astr) {
((*m_luaengine).*lualoadstringf)(astr);
}
static int luagetintvar(const char *astr) {
int retval = ((*m_luaengine).*luagetintvarf)(astr);
return retval;
}
static double luagetdoublevar(const char *astr) {
double retval = ((*m_luaengine).*luagetdoublevarf)(astr);
return retval;
}
static std::string luagetstringvar(const char *astr) {
std::string retval = ((*m_luaengine).*luagetstringvarf)(astr);
return retval;
}
}; // end class luacall
#endif // MAME_LUACALL_H
/***************************************************************************
luacall.cpp
Utility class for calling lua functions
***************************************************************************/
#include "emu.h"
#include "luacall.h"
lua_engine *luacall::m_luaengine;
void (lua_engine::* luacall::lualoadstringf) (const char * astr);
int (lua_engine::* luacall::luagetintvarf) (const char *astr);
double (lua_engine::* luacall::luagetdoublevarf)(const char *astr);
std::string (lua_engine::* luacall::luagetstringvarf)(const char *astr);
luaengine.h:
int luagetintvar( const char *astr);
double luagetdoublevar( const char *astr);
std::string luagetstringvar( const char *astr);
and in luaengine.cpp:
luacall::m_luaengine = this;
luacall::lualoadstringf = &lua_engine::load_string;
luacall::luagetintvarf = &lua_engine::luagetintvar;
luacall::luagetdoublevarf = &lua_engine::luagetdoublevar;
luacall::luagetstringvarf = &lua_engine::luagetstringvar;
int lua_engine::luagetintvar ( const char *astr) { return sol()[astr]; };
double lua_engine::luagetdoublevar( const char *astr) { return sol()[astr]; };
std::string lua_engine::luagetstringvar( const char *astr) { return sol()[astr]; };
so then I can do stuff like:
// call lua with a string to execute:
char buffer[128];
snprintf(buffer,128,"if drawdot then drawdot( %f, %f ) end", xcoord, ycoord);
luacall::lualoadstring(buffer);
// get the value from a double var:
printf("Get Double %f\n",luacall::luagetdoublevar("testdouble"));
//some indirection: get a double var from the name stored in the variable named by teststring2
printf("Testing luagetstring: value for %s %f\n",
luacall::luagetstringvar("teststring2").c_str(),
luacall::luagetdoublevar(luacall::luagetstringvar(luacall::luagetstringvar("teststring2").c_str()).c_str()));
// get the value from a integer var:
printf("Get Int %d\n",luacall::luagetdoublevar("testint"));
If the variable isn't defined, it seems to just return 0, 0.0 or the empty string. Testing luagetstring: value for 0.000000
Get Double 0.000000
Get Int 0
[MAME]> testdouble=5.29
[MAME]> testint=300
[MAME]> teststring2="orange"
[MAME]> orange="grape"
[MAME]> grape=777
[MAME]>
Testing luagetstring: value for orange 777.000000
Get Double 5.290000
Get Int 300
|
|
|
|
Joined: Feb 2014
Posts: 1,124 Likes: 193
Very Senior Member
|
OP
Very Senior Member
Joined: Feb 2014
Posts: 1,124 Likes: 193 |
I think I may have solved the mystery of the missing bottom line. The font data is stored as 8 bits, with the bottom line saved as 3 bytes. These bytes go into a shift register when written to c001,c002 and c003 and they get shifted out at c000. So now you can see the bottom of the character [: so at 2708 DE gets loaded with C001 and C gets 2 so we transfer 3 bytes to c001,c002,c003 with the BLOCK instruction. then at 2714 we read the value at C000 for our 9th pin, the other 8 bits coming from LDAX (HL+). It seems to work for the self test, anyway.
void e05a30_device::write(offs_t offset, uint8_t data)
{
LOG("%s: e05a30_w([0xC0%02x]): %02x\n", machine().describe_context(), offset, data);
switch (offset) {
case 0x0:
case 0x1:
case 0x2:
case 0x3:
c000_shift_register &= ~(0xff << ((3-offset)*8));
c000_shift_register |= (data << ((3-offset)*8));
break;
...
uint8_t e05a30_device::read(offs_t offset)
{
uint8_t result = 0;
LOG("%s: e05a30_r([0xC0%02x]): ", machine().describe_context(), offset);
switch (offset) {
case 0x0:
c000_shift_register <<= 1; // put shift before the capture
result = (c000_shift_register & 0x1000000) ? 0x80 : 0x0;
break;
|
|
|
|
Joined: Feb 2014
Posts: 1,124 Likes: 193
Very Senior Member
|
OP
Very Senior Member
Joined: Feb 2014
Posts: 1,124 Likes: 193 |
So if we can print 9 bits of the printhead, why not see if ESC ^ 9-pin graphics mode works: According to the ESC P manual, the second byte's LSB is the 9th pin, but it's actually the MSB, just as in the printer internals.
1 GOTO 10
5 X = PEEK( (12*16+1)*256 ) : P = 12*256*16+9*16 : FOR I=1 TO LEN(A$) : POKE P,ASC(MID$(A$,I,1)):NEXT:RETURN
10 REM APPLE PARALLEL CARD, READ FROM C100 SETS UP STROBE, THEN POKE C090 WILL SEND CHARACTERS
100 N = 120 * 3 : N1=((N/256)-INT(N/256))*256 :N2=INT(N/256) :? N,N1,N2:A$=CHR$(27)+"^"+CHR$(1)+CHR$(N1)+CHR$(N2) : GOSUB 5
110 FOR J = 1 TO N/2 : A$=CHR$(1+4+(1+4)*16)+CHR$(128) : GOSUB 5 : A$=CHR$(2+8+(2+8)*16)+CHR$(128):GOSUB 5:NEXT:A$=CHR$(10):GOSUB 5
Although, come to think of it, this probably worked before the 9-pin fix since it's not going through the shift register 8-)
|
|
|
|
Joined: Mar 2001
Posts: 17,234 Likes: 259
Very Senior Member
|
Very Senior Member
Joined: Mar 2001
Posts: 17,234 Likes: 259 |
Can you submit a pull request for the shift register fix? That would be great
|
|
|
|
Joined: Feb 2014
Posts: 1,124 Likes: 193
Very Senior Member
|
OP
Very Senior Member
Joined: Feb 2014
Posts: 1,124 Likes: 193 |
Sure, RB! (if I can get my git straightened up again 8-) I managed to get the font looking improved, but it still isn't quite right. The ap2000 does the NLQ fonts by printing one sequence of 9 bits, feeding the paper by 1/216" then printing the next sequence of 9 bits. It's kinda hacky yet, but I do like the little "circles" look on the i and the r and the 2. This is at 240x144 dots:
|
|
|
|
Joined: Mar 2001
Posts: 17,234 Likes: 259
Very Senior Member
|
Very Senior Member
Joined: Mar 2001
Posts: 17,234 Likes: 259 |
Neat! I love those little circles too
|
|
|
|
Joined: Feb 2014
Posts: 1,124 Likes: 193
Very Senior Member
|
OP
Very Senior Member
Joined: Feb 2014
Posts: 1,124 Likes: 193 |
Ok I made a PR:
ap2000 add shift register for c000 - fixes the missing 9th pin line #7366
I cloned a fresh repo so I wouldn't make a mess.
It's strange, testing it out but the keys stopped working, like holding keypad 7 (FF) when starting up to get it to go into self test mode. And holding down keypad 0 to toggle online doesn't work either.
|
|
|
1 members (Stick),
219
guests, and
1
robot. |
Key:
Admin,
Global Mod,
Mod
|
|
Forums9
Topics9,328
Posts122,128
Members5,074
|
Most Online1,283 Dec 21st, 2022
|
|
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!
|
|
|
|